如何在matplotlib中制作这样的情节,为了简单起见,我正在尝试(np.log10(df['amount'].dropna().values))
但x标签是对数刻度(不是原始刻度),我想要像David Robinson的情节,这里&# 39;是我的
label price growth
A 90 10%
B 32 32%
C 3 22%
D 0.3 16%
E 1 10%
我想要的是这样的东西
答案 0 :(得分:2)
您可以使用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())