繁体   English   中英

Python Seaborn Relplot 科学记数法

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM