在我的一张图中,我使用了次轴。我的代码创建两个不同的图例,并在我的图形中显示图例。这是我的代码:
fig3 = plt.figure()
ax3 = fig3.add_subplot(111)
ax4 = fig3.add_subplot(111)
ax4 = ax3.twinx()
line6 = ax3.plot(threshold, different_costs, '-r', label = 'Costs differences', linewidth = 2.0)
line7 = ax4.plot(threshold, costs1, '-b', label = 'Costs of Model 1 (OFF)', linewidth = 2.0)
line9 = ax4.plot(threshold, costs2, '-y', label = 'Costs of Model 2 (STANDBY)', linewidth = 2.0)
ax3.set_xlabel("Threshold")
ax3.set_ylabel("Costs savings")
ax4.set_ylabel("Total costs")
plt.suptitle("Costs savings of using MODEL 1")
plt.legend()
plt.show()
如何创建一个带有三个标签的图例?我怎样才能在图表之外显示这个传奇呢?
在这部分代码中:
要将所有行放到同一个图例上,请编写:
要想让你的传说脱离情节,请参考这个答案How to put the legend out of the plot,你可以写:
对于一些示例数据:
相关问题 更多 >
编程相关推荐