Python Seaborn Relplot科学记数法

2024-10-03 13:27:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个海生的故事情节。我想展示科学记数法。目前,图像在x和y刻度上占据了很大的空间。我想通过将坐标轴转换成科学符号来最小化它

我的代码:

sns.relplot(x='Vmpp',y='cVmpp',data=cdf)

enter image description here

我的解决方案和当前输出:

#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'

enter image description here


Tags: 图像dataplot科学cdfsnsdid刻度
1条回答
网友
1楼 · 发布于 2024-10-03 13:27:33

^{}是一个figure-level函数。如果您只需要简单的散点图,您可能需要使用^{}

在任何情况下,都可以使用通常的matplotlib方法微调绘图。特别是,可以使用^{}强制对任何记号标签编号进行科学标记

我还建议设置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);

enter image description here

编辑: 正如@mwaskom指出的,您也可以通过sns.relplot()以这种方式更改记号标签,在本例中,只需在格式化程序之前调用plotting函数。您不需要指定轴,因为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));

相关问题 更多 >