我正在繪製使用pandas
數據框的散點圖。這工作正常,但我想使用seaborn
主題和特殊功能。當我繪製調用seaborn的相同數據點時,y軸幾乎不可見。 X軸值範圍從5000-15000
,而Y軸值在[-6:6]*10^-7
。seaborn對熊貓的y軸縮放
如果我將y軸值乘以10^6,它們將正確顯示,但使用seaborn
繪製的實際值在seaborn
生成的繪圖中保持不可見/無法區分。
我怎麼能seaborn
,使y軸值自動生成的打印比例?
還有一些行甚至包含NaN
,而不是在這種情況下,如何在繪圖時忽略這一點,缺少手動除去包含NaN
的行。
下面是我用來繪製的代碼。
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("datascale.csv")
subdf = df.loc[(df.types == "easy") & (df.weight > 1300), ]
subdf = subdf.iloc[1:61, ]
subdf.drop(subdf.index[[25]], inplace=True) #row containing NaN
subdf.plot(x='length', y='speed', style='s') #scales y-axis correctly
sns.lmplot("length", "speed", data=subdf, fit_reg=True, lowess=True) #doesn't scale y-axis properly
# multiplying by 10^6 displays the plot correctly, in matplotlib
plt.scatter(subdf['length'], 10**6*subdf['speed'])
目前還不清楚你的意思是「y軸保持不可見」,並且它不可能運行你的代碼... – mwaskom