【发布时间】:2019-03-03 00:21:53
【问题描述】:
当a tick的文字标签过长时,我们经常需要旋转它以防止文字重叠。我在这里遇到的问题是,当 matplotlib 长于图形大小时,它只会显示其中的一部分。
1.有没有办法扩展图表底部的边距,使其适合所有文本?
2。如果横向更可取,有没有办法将文本分成两行或多行,这样它们就不会重叠?
plt.figure(figsize=(50,50))
但它只会导致图表中每个元素的比例增加。
我尝试用
调整marginplt.tight_layout()
但它似乎与图形内容进行了权衡。最后想到了adjusting the aspect ratio,不过好像只和图的内容有关。
我目前正在使用 matplotlib 2.2.2 和 您可以使用以下代码 (original) 重现上图:
import numpy as np
import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
womenMeans = (25, 32, 34, 20, 25)
menStd = (2, 3, 4, 1, 2)
womenStd = (3, 5, 2, 3, 3)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars: can also be len(x) sequence
# plt.figure(figsize=(500,20))
p1 = plt.bar(ind, menMeans, width, yerr=menStd)
p2 = plt.bar(ind, womenMeans, width,
bottom=menMeans, yerr=womenStd)
plt.ylabel('Scores')
plt.title('Scores by group and gender')
# plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
plt.yticks(np.arange(0, 81, 10))
plt.legend((p1[0], p2[0]), ('Men', 'Women'))
plt.xticks(ind, ('It shows up perfectly fine in Jupyter Notebook', 'how can I adjust "some setting" so that I can see all these?', 'G3', 'G4', 'G5'))
plt.tick_params(labelrotation=90)
# plt.savefig('Example.jpeg')
# plt.tight_layout()
plt.show()
【问题讨论】:
-
查看坐标轴位置和边界
标签: python matplotlib plot graph