I am new to using PTVS for my Python code. I previously used Spyder as it came along with the Anaconda distribution. Here is the issue I am having.
I am trying to create two plots, and show them in separate windows at the same time. A simple example is.
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5])
plt.show()
plt.plot([2,2,2,2,2])
plt.show()
But the second plot does not show up unless I close the first plot. Similarly for a larger script, the rest of the code chunk after plt.show() does not execute if I don't close the plot. I tried executing without debugging and it does not work. However, when I run the same code in Ipython interactive window, all the code executes and I can see both plots as inline, yet it is not what I want. I want to all the code to run creating as many plots as needed in different windows without me interrupting like closing the plot for the rest of the code to run. I can still do it in Spyder, but I want to switch to Visual Studio completely and this issue is bugging me.
Any help would be appreciated. Thanks in advance.
I haven't done this in Visual Studio but with Matplotlib you can use a non-blocking call to show
. The draw
method does not block but if you don't end the calls by doing a show
then the graph window will immediately close.
import matplotlib.pyplot as plt
plt.figure(1)
plt.plot([1,2,3,4,5])
plt.show(block=False)
# Create a new figure to show the extra information.
# http://matplotlib.org/users/pyplot_tutorial.html#working-with-multiple-figures-and-axes
plt.figure(2)
plt.plot([2,2,2,2,2])
plt.show()
Here is a related question on the same topic.
Personally I use subplots
as shown in the matplotlib examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With