【发布时间】:2018-10-15 08:35:52
【问题描述】:
我正在尝试重现此图 - 每个点都有一个箱线图的线图:
但是,线图总是从原点开始,而不是从第一个 x 刻度开始:
我已将我的数据结构收集在一个 pandas 文件中,每个列标题是 k_e(x 轴的),该列是所有数据点。
我正在绘制每列的平均值和箱线图,如下所示:
df = df.astype(float)
_, ax = plt.subplots()
df.mean().plot(ax = ax)
df.boxplot(showfliers=False, ax=ax)
plt.xlabel(r'$k_{e}$')
plt.ylabel('Test error rate')
plt.title(r'Accuracies with different $k_{e}$')
plt.show()
我参考了下面的链接,因此我通过了“斧头”位置,但这没有帮助。
plot line over boxplot using pandas DateFrame
编辑:这是一个最小的例子:
test_errors_dict = dict() np.random.seed(40)
test_errors_dict[2] = np.random.rand(20)
test_errors_dict[3] = np.random.rand(20)
test_errors_dict[5] = np.random.rand(20)
df = pd.DataFrame(data=test_errors_dict)
df = df.astype(float)
_, ax = plt.subplots()
df.mean().plot(ax=ax)
df.boxplot(showfliers=False, ax=ax)
plt.show()
结果: Imgur
如上图,线图与箱线图不对齐
【问题讨论】:
-
确保提供minimal reproducible example,以便您的问题可以重现。
-
@ImportanceOfBeingErnest 完成!
-
啊好吧,这和this one类似的问题。
标签: python pandas matplotlib visualization