如何在matplotlib中制作散点图对数刻度(带原始刻度中的标签)
问题描述:
如何在matplotlib中制作一些这样的绘图,为了简单起见,我试图使用(np.log10(df['amount'].dropna().values))
,但x标记是对数刻度(不是原始刻度),我要像大卫·罗宾逊的情节,这是我如何在matplotlib中制作散点图对数刻度(带原始刻度中的标签)
label price growth
A 90 10%
B 32 32%
C 3 22%
D 0.3 16%
E 1 10%
我想是这样的
答
你可以使用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())
我要的是价格对数刻度,为什么你在非常小的 –
字体我asumming'PLT .scatter()'解决方案 –
只是改变剧情的大小和方面 – Gayatri