Y axis label missing when saving matplotlib file as png

Viewed 4629

I'm trying to save my matplotlib graph as a png. When I run my program, I see the graph appear due to plt.show() and this graph has the y axis label. But then when I go look at the created .png file the y axis label is missing.

png file

graph

Code:

plt.plot_date(times, tps, 'b-', xdate=True)

plt.xlabel('Time', fontsize=20)
plt.ylabel('Transactions per Second', fontsize=20)
title = str(sys.argv[1])
title = title[title.rfind('/') + 1:]

plt.savefig(title + ".png")
plt.show()
1 Answers

The default figure size is [6.4, 4.8] inches, so it is smaller than your font and y-values. You can make the figure size bigger and it will display the y-axis as well.

plt.figure(figsize=(20,10))
plt.plot_date(times, tps, 'b-', xdate=True)
Related