![](/img/trans.png)
[英]Why does matplotlib require setting log scale before plt.scatter() but not plt.plot()?
[英]How to make scatter plot log scale (with label in original scale) in matplotlib
您可以使用seaborn來做到這一點:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
%matplotlib inline
數據:
label price growth
0 A 90.0 0.10
1 B 32.0 0.32
2 C 3.0 0.22
3 D 0.3 0.16
4 E 1.0 0.10
情節:
ax = sns.lmplot('price', # Horizontal axis
'growth', # Vertical axis
data=data, # Data source
fit_reg=False, # Don't fix a regression line
size = 5,
aspect =1 ) # size and dimension
plt.title('Example Plot')
# Set x-axis label
plt.xlabel('price')
plt.xscale('log')
# Set y-axis label
plt.ylabel('growth')
def label_point(x, y, val, ax):
a = pd.concat({'x': x, 'y': y, 'val': val}, axis=1)
for i, point in a.iterrows():
ax.text(point['x']+.02, point['y'], str(point['val']))
label_point(data.price, data.growth, data.label, plt.gca())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.