【发布时间】:2020-12-01 11:05:52
【问题描述】:
我用 python 绘制了一个带有两个 y 轴的图形。但是,我希望两条线之间有更多的空间,辅助 y 轴位于图表的顶部。
这是我的代码:
x = data['Data'].tolist()
y = data['Excess Return'].tolist()
z=data['EPU shock'].tolist()
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
curve1 = ax1.plot(x, y, label='Excess Return', color='r')
curve2 = ax2.plot(x, z, label='EPU shock', color='b')
lines_1, labels_1 = ax1.get_legend_handles_labels()
lines_2, labels_2 = ax2.get_legend_handles_labels()
lines = lines_1 + lines_2
labels = labels_1 + labels_2
ax1.legend(lines, labels, loc="lower center", borderaxespad=-5, ncol=2)
plt.title("European Union")
plt.show()
输出:
但我想要这样的东西:
【问题讨论】:
-
这两张图到底有什么区别?我看不到任何
-
这些图片是一样的
-
我已经更正了
-
您可以尝试以数据不重叠的方式设置 yticks、yticks label 和 ylim。它也可以通过根据数据的平均值和标准来确定值来自动化。
标签: python matplotlib graph