条形图使用matplotlib调整文本和条带大小 - python

时间:2022-04-20 23:40:07

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?

有办法解决这个问题吗?

2 个解决方案

#1


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.bar it looks like you can play with the width attribute.

对于条形宽度,如果你使用pyplot.bar看起来你可以使用width属性。

#2


Take a look at subplots_adjust, or just use axes([left,bottom,width,height]).

看看subplots_adjust,或者只使用轴([left,bottom,width,height])。

#1


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.bar it looks like you can play with the width attribute.

对于条形宽度,如果你使用pyplot.bar看起来你可以使用width属性。

#2


Take a look at subplots_adjust, or just use axes([left,bottom,width,height]).

看看subplots_adjust,或者只使用轴([left,bottom,width,height])。