【发布时间】:2020-07-16 14:08:19
【问题描述】:
我希望在 matplotlib 中用箱线图覆盖散点图。我已经创建了图表,但 x 轴不匹配 - 导致散点图显示的点在箱线图的 x 轴左侧移动了 1 个刻度。下面是我的代码。
fig, ax = plt.subplots()
ax.scatter(traits_5, data_df[traits_5].loc[y])
ax = greats_df[traits_5].boxplot ( showfliers=False , column=traits_5)
plt.ylabel ( 'Percentile Score' )
plt.title ( "Distribution of The Greats' Scores" )
ax.yaxis.set_major_formatter(mtick.PercentFormatter(1))
plt.show ()
错误是否可能来自绘制数据的两种不同方法?我使用 matplotlib 绘制散点图,使用 pandas 绘制箱线图。 Matplotlib 在 x 轴上绘制行,而我希望沿 x 轴绘制列。
从上面的代码看下面的输出图像。
【问题讨论】:
-
请提供完整的 MCVE。通过查看代码,我不知道您的数据是什么。您可以使用
np.random.randn或类似方法来生成列。 -
很高兴看到
PercentFormatter被使用 :)
标签: python matplotlib