簡體   English   中英

如何在matplotlib中制作散點圖日志比例尺(帶有原始比例的標簽)

[英]How to make scatter plot log scale (with label in original scale) in matplotlib

如何在matplotlib中制作這樣的圖,為了簡化(np.log10(df['amount'].dropna().values)) ,我嘗試了(np.log10(df['amount'].dropna().values))但是x標簽是對數刻度(不是原始刻度) ,我想要類似David Robinson的圖,這是我的

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()) 

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM