I'm trying to set the aspect ratio of a plot but including the title and axis labelings. I know that figsize is referring to the axis only. I already tried plt.tight_layout, plt.subplots_adjust and fig.set_size_inches but none is working for my problem. I also tried to increase the input aspect ratio, testing if the output ratio follows a rule.
Here is a minimal, reproducible example:
Finally I need a .jpg-Output file that is 320mmx70mm (w x h). So the aspect ratio should be 320/70=4,57. As at the moment the figsize is only referring to the axis, the aspect ratio changes in the output to 1960px/523px = 3,75. My goal is to have an output aspect ratio of 4,57.
fig = plt.figure(figsize=[320/25.4, 70/25.4])
ax = fig.add_axes([0,0,1,1])
langs = ['C', 'C++', 'Java', 'Python', 'PHP']
students = [23,17,35,29,12]
ax.bar(langs,students)
ax.set_title('Title', loc='left', fontdict=dict(fontsize=20, fontweight='bold'))
#plt.show()
plt.savefig('example.jpg', dpi=150, bbox_inches="tight")