Using matplotlib.pyplot
, I want to create a barplot, and save it to an image without axes, borders and additional whitespace around. The answers to Save spectrogram (only content, without axes or anything else) to a file using Matloptlib and all the linked questions and respective answers seem not to work for barplots.
So far I got:
import matplotlib.pyplot as plt
fig,ax = plt.subplots(1)
fig.subplots_adjust(left=0,right=1,bottom=0,top=1)
fig.patch.set_facecolor('xkcd:mint green')
ax.set_facecolor('xkcd:salmon')
ax.axis('off')
ax.bar(1,1,1,-1,alpha=1, align='center', edgecolor='black')
ax.bar(2,1,1,-2,alpha=1, align='center', edgecolor='black')
ax.axis('off')
fig.savefig('test.png', dpi=300, frameon='false', pad_inches=0.0,bbox_inches='tight')
which has three issues:
- There is some remaining whitespace at the left,top and right.
- The figure seems to be cut at the bottom, as the bottom line of the lower bar is thinner than the others.
- The aspect ration should be 1:1 and seems to be off.