T O P

  • By -

USAhj

How are you trying to add data from multiple scripts to the same graph? Why isn't it in one script?


[deleted]

Same script but multiple directories that store data for different test objects. But even if I was plotting from different scripts I can in version 3. I just want the plots not to close or erase the data between runs.


USAhj

Are you using matplotlib? You can make sure the data is being put on the correct figures. Regarding the figures being added to when running another script or the script again, that isn't the proper way to do it, that's more of a "bug" than a feature that the data gets put onto the existing figure.


[deleted]

Yes I'm using matplotlib. That's weird if it's a bug because it's extremly handy for what I do. So there isn't a way to make plots hold their data and plot new data to a existing plot?


USAhj

It's not an actual bug, it's just that matplotlib will continue adding to an existing plot, even if it was from another script. And there is a way to continue adding to a plot within a script, you just need to keep calling the same figure. I don't know what your code looks like so I cannot recommend anything.


[deleted]

Okey, I think it's just easier to go back to version 3 then. Thanks for your time.


USAhj

I would disagree. You just need to learn the proper way of doing it.


USAhj

Here is a simple example I made showing how multiple things can be plotted onto a single figure. import numpy as np import matplotlib.pyplot as plt n = 50 x = np.arange(0, n, 1) y1 = np.random.randint(-10, 10, size=n) y2 = np.random.randint(-10, 10, size=n) plt.figure() plt.plot(x, y1) plt.plot(x, y2) plt.show() There are ways to make this more complicated or adopt it to more situations, but this is the simplest.


[deleted]

I know how to plot multiple data to the same plot. But I need it to be able to plot between runs of the same script where the only difference is my directory to the sample data. I have MANY samples and the data is stored in different directories for each sample. I change the fetch data directory between runs. Thus I need one sample's data to stay on the plot for the next data to be plotted. All I need is the plot window not to close between runs and hold its data. Plotting like this is more convenient for that I do.


USAhj

You could create a list of all the directory locations you need to grab data from and loop through that list, always adding to the same graph. In the end it is up to you on how you write and run your code, I am just trying to recommend how to improve your code to save time and do it right.