from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
if __name__ == "__main__":
fig1 = ...
print("start plotting")
canvas = FigureCanvasQTAgg(fig1)
canvas.draw()
canvas.show()
I have written to function which returns a matplotlib.figure object. I have run the above script. It has crashed Python. How do I do this?
The reasons I have worked with FigureCanvasQTAgg and matplotlib.figure instead of working with matplotlib.pyplot is that the Figure object also allow me to do something like
with PdfPages(...) as pdf_writer:
canvas = FigureCanvasPDF(fig1)
pdf_writer.savefig(fig1)
pdf_writer.savefig(fig1)
which writes out two copies of the same figure in a single pdf file. Also it would allow me to write write multiple figures into the same PDF. I am unaware of any way we can do this using only matplotlib.pyplot