使用 matplotlib - python 调整文本和条宽的条形图大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/712082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Barchart sizing of text & barwidth with matplotlib - python
提问by Gern Blanston
I'm creating a bar chart with matplotlib-0.91 (for the first time) but the y axis labels are being cut off. If I increase the width of the figure enough they eventually show up completely but then the output is not the correct size.
我正在使用 matplotlib-0.91(第一次)创建条形图,但 y 轴标签被切断。如果我足够增加图形的宽度,它们最终会完全显示出来,但输出的大小不正确。
Any way to deal with this?
有什么办法处理这个吗?
回答by monkut
I think I ran into a similar problem.
我想我遇到了类似的问题。
See if this helps adjusting the label's font size:
看看这是否有助于调整标签的字体大小:
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
fontsize2use = 10
fig = plt.figure(figsize=(10,5))
plt.xticks(fontsize=fontsize2use)
plt.yticks(fontsize=fontsize2use)
fontprop = fm.FontProperties(size=fontsize2use)
ax = fig.add_subplot(111)
ax.set_xlabel('XaxisLabel')
ax.set_ylabel('YaxisLabel')
.
<main plotting code>
.
ax.legend(loc=0, prop=fontprop)
For the bar width, if your using pyplot.barit looks like you can play with the width attribute.
对于条形宽度,如果您使用pyplot.bar看起来您可以使用 width 属性。
回答by Jouni K. Sepp?nen
Take a look at subplots_adjust
, or just use axes
([left,bottom,width,height])
.
看看subplots_adjust
,或只是使用。axes
([left,bottom,width,height])