Aug-02-2018, 08:20 AM
How to plot data to the same figure for every run?
Hi
I wonder how it is possible to plot data to the same figure in python for every run. When I run the code below once, it will plot some data in figure 1. When I run it the second time I want the second set of random numbers plotted on top of the first set in figure 1 (like Matlab would behave when there is a hold on in the end). Instead Python opens another figure 1 and plots the secoond set there. Can I somehow find figure handles and check if figure 1 is open already and then use this as parameter in the plotting function? Or is there a more simple way? The code below is a mini example and plotting another time in the same run is not a solution for me.
Hi
I wonder how it is possible to plot data to the same figure in python for every run. When I run the code below once, it will plot some data in figure 1. When I run it the second time I want the second set of random numbers plotted on top of the first set in figure 1 (like Matlab would behave when there is a hold on in the end). Instead Python opens another figure 1 and plots the secoond set there. Can I somehow find figure handles and check if figure 1 is open already and then use this as parameter in the plotting function? Or is there a more simple way? The code below is a mini example and plotting another time in the same run is not a solution for me.
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(1, 10, 10)
y = np.random.randn(10)
plt.figure(1)
plt.plot(x, y)
plt.ylabel('signal')
plt.xlabel('time')
plt.show()
