[英]Python, Seaborn: Logarithmic Swarmplot has unexpected gaps in the swarm
让我们看一个用 Python 3.5 和 Seaborn 制作的 swarmplot 对一些数据(它存储在 Pandas 数据帧 df 中,列标签存储在另一个类中。这暂时无关紧要,只需看一下图):
ax = sns.swarmplot(x=self.dte.label_temperature, y=self.dte.label_current, hue=self.dte.label_voltage, data = df)
现在,如果在 y 轴上以对数刻度绘制,则数据更具可读性,因为它已经过去了几十年。 因此,让我们将缩放比例更改为对数:
ax.set_yscale("log")
ax.set_ylim(bottom = 5*10**-10)
好吧,我对群中的间隙有疑问。 我猜他们在那里是因为他们在创建绘图时考虑了线性轴并且点不应该在那里重叠。 但是现在它们看起来有点奇怪,并且有足够的空间来组成 4 个相同的群体。 我的问题是:如何强制seaborn
重新计算点的位置以创建更好看的群?
mwaskom在评论中向我暗示如何解决这个问题。 它甚至在 swampplot doku 中说:
请注意,正确排列点需要在数据和点坐标之间进行准确的转换。 这意味着在绘制群图之前应该设置非默认轴限制。
将现有轴设置为对数刻度并将其用于绘图:
fig = plt.figure() # create figure
rect = 0,0,1,1 # create an rectangle for the new axis
log_ax = fig.add_axes(rect) # create a new axis (or use an existing one)
log_ax.set_yscale("log") # log first
sns.swarmplot(x=self.dte.label_temperature, y=self.dte.label_current, hue=self.dte.label_voltage, data = df, ax = log_ax)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.