Barchart sizing of text & barwidth with matplotlib - python
-
23-08-2019 - |
Question
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.
Any way to deal with this?
Solution
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.
OTHER TIPS
Take a look at subplots_adjust
, or just use axes
([left,bottom,width,height])
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow