1

I'm using the latest matplotlib, version 2.0.0, installed via pip on Mac OSX Sierra. The problem is that the following example does not work as expected as no figure is shown. Note that I'm calling show() on the figure1 object because I want to show only figure1. If I use plt.show() it works but it shows both figure1 and figure2 which I don't want.

import matplotlib.pyplot as plt

figure1 = plt.figure()

# I need figure2 for something else but I don't want to show it.
figure2 = plt.figure()

figure1.show()

# The following would work, but I want to show
# only figure1 and not also figure2.
# plt.show()
njk
  • 645
  • 2
  • 10
  • 19
  • maybe this is what you're looking for http://stackoverflow.com/questions/2397791/how-can-i-show-figures-separately-in-matplotlib – Japu_D_Cret Apr 21 '17 at 07:55

1 Answers1

2

figure.show() makes sense in interactive mode, not for permanently showing a figure. So you need to use plt.show(). In order not to show the second figure, you may close it beforehands,

plt.close(figure2)
plt.show()
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • I still need `figure2` for something else. Is there a way I can show only `figure1` without losing `figure2`. I mean I need `figure2` because say I want to save it to disk without showing it, can I still use it if I close it? – njk Apr 21 '17 at 08:18
  • Uhm... are you sure about this? It seems like I'm still able to save it, even after calling `plt.close('all')` – njk Apr 21 '17 at 08:54
  • You're right, even better. So just close the figure you don't want to show, and that's it. – ImportanceOfBeingErnest Apr 21 '17 at 09:18