【发布时间】:2021-01-19 09:08:16
【问题描述】:
我想在 matplotlib python 中使用三个带有三个 y 轴的条。
我使用两个带有两个 y 轴的条形图,一切正常 Ref. ,
我想用黑色添加第三个刻度。
请您帮忙。
width = 0.25
fig, ax1 = plt.subplots()
ind = np.arange(len(r2_score1))
print 'r2_score1', r2_score1
rects1 = ax1.bar(ind, r2_score1, width, color = 'b')
ax1.set_xticks(ind+width)
ax1.set_xticklabels(names, fontsize=14)
ax1.set_ylabel('r2_score', color='b')
for tl in ax1.get_yticklabels():
tl.set_color('b')
ax2 = ax1.twinx()
rects2 = ax2.bar(ind + width, time_model, width, color = 'r')
ax2.set_ylabel('Time (s)', color='r')
for tl in ax2.get_yticklabels():
tl.set_color('r')
ax3 = ax2.twinx()
rects3 = ax3.bar(ind + width+ width, rmse, width, color = 'k')
ax3.set_ylabel('rmse', color='k')
for tl in ax3.get_yticklabels():
tl.set_color('k')
【问题讨论】:
-
这在 matplotlib 的 parasite axis demo 中得到了很好的解释——他们甚至提供了 a second version 来解决这个问题。
标签: python matplotlib bar-chart axes