-1

I am so new here and I have a very basic question I have, I need to see several plots using matplotlib in python, but in order to see the next plot I need to first close the previous one, how can I avoid that? and have all plots shown at the same time?

p.s: I don't want to have them in a same plot, I plot totally irrelevant things :)

B B
  • 23
  • 4

1 Answers1

-2

if you're using jupyter notebook, use plt.subplot(), do something like:

plt.subplot(2, 1, 1)
#some plotting

plt.subplot(2, 1, 2)
#some other plotting

plt.show()

subplot(2, 1, #) is two rows, and one column, # here is the which slot you're using.

for more flexibility, try plt.subplots().

f, axarr = plt.subplots(2)
axarr[0].plot()
axarr[1].plot()

f is the current figure object you're working on, axarr is an array of axis, you can plot on each axis.

  • Providing an answer which does not provide more information than any answer to the duplicate questions is not helpful. If you think that any aspect of this particular question is not covered in the duplicates, you should only focus on that part (Which I suspect isnt the case here). Otherwise providing an answer to the duplicate questions is also possible. – ImportanceOfBeingErnest Jun 09 '17 at 17:12
  • @ImportanceOfBeingErnest I answered the question before realizing it's a duplicate and only for the purpose of helping out people who's having trouble starting out on coding. If that's the reason for the downvote, thank you very much, you're truly the man. – Bubble Bubble Bubble Gut Jun 09 '17 at 17:24
  • I wouldn't have downvoted if this question hadn't been very obviously already been asked before and if duplicates wouldn't have been tremendously easy to find on google. By doing this, you're not helping anyone. Not the community for sure, but also not the questioner, as he is rewarded for asking a poorly researched question, which if everyone would do, destroys the site such that in the long run even his question would could be answered anymore. – ImportanceOfBeingErnest Jun 09 '17 at 18:05