[英]How does one display a legend on a pdf in matplotlib without it overlapping the x-axis of some graphs?
I have been able to create a series of plots (6 x 3) in matplotlib and save them to a PDF. 我已经能够在matplotlib中创建一系列绘图(6 x 3)并将其保存为PDF。 I would like a single legend per page.
我希望每页有一个图例。 However, each legend overlasp the x-axis of the bottom center plot on each page.
但是,每个图例会使每页底部中心图的x轴重叠。 I tried changing the size of the image
我尝试更改图像的大小
fig = plot.figure(figsize=(8.27, 11.69), dpi=100)
but that did not work. 但这没有用。 I am using the following command to generate the legend:
我正在使用以下命令生成图例:
plot.figlegend((p1[0], p2[0]), (assay1, assay2), loc='lower center', ncol=3, labelspacing=0)
You could make more space at the bottom of the figure by making the axes smaller either by using a 7 by 3 array of subplots or by each axis size directly. 您可以通过使用7 x 3的子图数组或直接按每个轴的大小来减小轴的大小,从而在图的底部留出更多空间。
fig = figure(figsize=(8.27, 11.69), dpi=100)
for i in range(1,19):
subplot(7,3,i) # 7 by 3 subplot
p1 = plot([1,2,3])
p2 = plot([4,5,6])
figlegend((p1[0], p2[0]), ('assay1', 'assay2'), loc='lower center', ncol=3, labelspacing=0)
tight_layout()
savefig('test.png')
show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.