0

I recently switched to Pycharm from Spyder. I have a code that basically plots a lot of things, but here is how the first part goes

======================

A = numpy array
B = another numpy array

plt.plot(A,B)
plt.show()

some code here that takes a very long time to run and creates two more (different) arrays C,D.

plt.plot(C,D)
plt.show()

=======================

Now, my problem is that PyCharm opens a separate window to show me my figures, and while this figure is being shown, the code pauses in the background. So, while the plot (A,B) is being shown to me, the 'very long time to run' code does not even begin running. Pycharm clearly says that the figure shown is 'Figure 1', so I'm assuming that it should also be able to show figures 2,3,4... too. However, because the code pauses right after the first plt.show() until I close the window, I never get to see all my plots together in that window. As a result, It gets very tedious when I attempt to look through a few plots at once, and increases the run time of my code by a lot, as I have to manually 'restart' it after each plt.show().

Is there a way I can set Pycharm to not stop at each plt.show(), so that it runs through my entire code without pausing and creates all my plots as Figure 1,2,3,4... on that popup window?

I've gone through the different view modes of Pycharm, and gone through the settings, but I haven't been able to find a section about figures, and I'm wondering if the cause is matplotlib and how it interacts with Pycharm instead? Surely its an easy fix, I just haven't seem to find anything in the settings or this specific problem online.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Berkin
  • 1
  • 1
  • Set pycharm to use scientific mode (pycharm pro), or set a different backend like `matplotlib.use('Agg')` https://stackoverflow.com/q/4930524/7758804 – Trenton McKinney Jun 11 '23 at 20:03
  • Check the [following post](https://stackoverflow.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue). – Rotem Jun 11 '23 at 20:04
  • 1
    `plt.show(block=False)` might also work, though I do not have PyCharm to test it. – jared Jun 11 '23 at 20:07

0 Answers0