0
import matplotlib.pyplot as plt
fig, ax = plt.subplots()

# do stuff here

fig = ax = None
del(fig, ax)

plt.show()

The None and del lines do not prevent the figure from showing. Is there any way to once I've created it? Is the only way to avoid showing a figure not creating it in the first place?

Forklift17
  • 2,245
  • 3
  • 20
  • 32
  • 1
    `plt.close(fig)`? – Mr. T Jan 28 '21 at 23:42
  • Don't call `plt.show()` at the end if you don't want the plot to be rendered and displayed on the screen. Also, instead of showing it to the user, you can silently save it to a png file using `plt.savefig('output.png')` instead of using `plt.show()`. – Dilawar Jan 28 '21 at 23:53
  • 2
    Maybe they want to show other windows with `plt.show`. Not every application is based on exactly one figure. – Mr. T Jan 28 '21 at 23:55
  • @Dilawar not calling ```plt.show()``` does not hide the plot. Mr. T's solution works. – Forklift17 Jan 28 '21 at 23:56

0 Answers0