简体   繁体   English

如何在matplotlib中的pdf上显示图例而不使其与某些图形的x轴重叠?

[英]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.

相关问题 Matplotlib:如何重新排列图表的 x 轴? - Matplotlib: How can I reorder the graphs' x-axis? 如何将 x 轴值转换为 matplotlib 条形图的图例 - How to turn x-axis values into a legend for matplotlib bar graph 如何在一个包含多个matplotlib直方图的图形中设置x轴的边界并仅创建一列图形? - how to set bounds for the x-axis in one figure containing multiple matplotlib histograms and create just one column of graphs? 当x轴是字符串时,如何让python matplotlib显示x轴坐标(右上角) - How to make python matplotlib display x-axis coordinates (right corner) when x-axis is a string 如何在Matplotlib X轴中显示日期而不是序列号 - How to display dates in matplotlib x-axis instead of sequence numbers 在一个折线图中显示三个图表并指定 x 轴和 y 轴的最佳方法是什么? - What is the best way to display three Graphs in one line chart and specify the x-Axis and y-Axis? Matplotlib:在指定的x轴范围内绘制两个图形 - Matplotlib: Plotting two graphs within a specified x-axis range Matplotlib多个图,x轴下方有额外空间 - Matplotlib multiple graphs, extra space underneath x-axis 绘制在matplotlib中共享x轴的两个图形 - Plotting two graphs that share an x-axis in matplotlib 如何使用matplotlib / seaborn和pandas数据框创建带有共享x轴的上下条形图 - how to create upside down bar graphs with shared x-axis with matplotlib / seaborn and a pandas dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM