简体   繁体   中英

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. I would like a single legend per page. However, each legend overlasp the x-axis of the bottom center plot on each page. 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.

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()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM