我有一个Python3.6代码,它产生两个图,一个有三个轴,另一个有两个轴。三轴的情节有一个细线的传说。Matplotlib减少带有两个y轴的锅的图线厚度?
不幸的是,第二图例具有厚度等于所述标签的高度行:
这里是第二图形的代码:在一个数字
两个曲线
如何减少图例中线条的粗细?
这似乎是代码没有达到岗位。
这就是:
#two plots on one figure
def two_scales(ax1, time, data1, data2, c1, c2):
ax2 = ax1.twinx()
ax1.plot(time, data1, 'r')
ax1.set_xlabel("Distance ($\AA$)")
ax1.set_ylabel('Atom Charge',color='r')
ax2.plot(time, data2, 'b')
ax2.set_ylabel('Orbital Energy',color='b')
return ax1, ax2
t = data[:,0]
s1 = data[:,3]
s2 = data[:,5]
fig, ax = plt.subplots()
ax1, ax2 = two_scales(ax, t, s1, s2, 'r', 'b')
def color_y_axis(ax, color):
for t in ax.get_yticklabels():
t.set_color(color)
return None
color_y_axis(ax1, 'r')
color_y_axis(ax2, 'b')
plt.title('Molecular Transforms')
patch_red = mpatches.Patch(color='red',label='Atom Charge')
patch_blue = mpatches.Patch(color='blue',label='Orbital Energy')
plt.legend(handles = [patch_red,patch_blue])
plt.draw()
plt.show()
name_plt = name+'-fig2.png'
fig.savefig(name_plt,bbox_inches='tight')
许多感谢的解决方案。问题现在已经解决了。 – Steve