I have a matplotlib.bar plot and I can't figure out how to space the bars further apa开发者_JS百科rt so the labels are readable.
Here is my code
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
def makePlot(self, data, labels, title, fileName):
plt.bar(range(1,len(data)+1), data, align="center")
plt.title(title)
plt.xticks(range(1, len(labels)+1), labels)
plt.savefig(fileName)
plt.clf()
You can change the size of the figure by calling plt.figure(figsize=(x,y))
where x
and y
are the width and height in inches. That line must be before you call plt.bar
.
Alternatively, you can make the label font smaller. You would do that by changing your call to xticks
to plt.xticks(range(1, len(labels)+1), labels, size='small')
.
One more thing to try is to use the plt.xlim() function to manually set the limits of the x axis.
精彩评论