[英]Python Seaborn Relplot Scientific notation
我有一個seaborn relplot。 我想顯示科學記數法。 目前,圖像在 x 和 y 刻度上占據了很大的空間。 我想通過將軸轉換為科學記數法來最小化它。
我的代碼:
sns.relplot(x='Vmpp',y='cVmpp',data=cdf)
我的解決方案和當前輸出:
#I tried a solution reported for the seaborn heatmap. It did produce a plot (I think heat plot?) but did not work.
sns.relplot(x='Vmpp',y='cVmpp',data=cdf,fmt='.2g')
當前輸出:
AttributeError: 'PathCollection' object has no property 'fmt'
sns.relplot()
是圖形級函數。 如果您只需要簡單的散點圖,您可能需要使用sns.scatterplot()
代替。
在任何情況下,您都可以以通常的 matplotlib 方式微調繪圖。 特別是,可以使用ax.ticklabel_format(axis='both', style='scientific', scilimits=(0, 0))
強制任何刻度標簽數字的科學記數法。
我還建議設置alpha
值,因為您有很多重疊點。 這是一個完整的例子:
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
titanic = sns.load_dataset('titanic')
fig, ax = plt.subplots()
ax.ticklabel_format(axis='both', style='scientific', scilimits=(0, 0))
sns.scatterplot(x='age', y='fare', data=titanic, alpha=0.5);
編輯:正如@mwaskom 指出的那樣,您也可以使用sns.relplot()
以這種方式更改刻度標簽,在這種情況下,只需在格式化程序之前調用繪圖函數。 您不需要指定軸,因為ticklabel_format()
通過matplotlib.pyplot
接口工作:
# [...] imports and data as above
sns.relplot(x='age', y='fare', data=titanic, alpha=0.5)
plt.ticklabel_format(axis='both', style='scientific', scilimits=(0, 0));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.