I solved the issue by changing
ax.savefig('file.png')
to
ax.figure.savefig('file.png')
I guess accessing the figure directly is one way to get to the savefig()
method for the barplot.
@WoodChopper also has a working solution, but it requires another import statement, and utilizing pyplot’s savefig()
directly.
Either solution does require setting matplotlib.use('Agg')
to get around the DISPLAY variable error. As the referenced post noted, this has to be set before importing other matplotlib libraries.