Plotting multiple figures using Plots.jl

Hi,

I would like to run a script in Visual Studio Code that plot different graphs in multiple figures (multiple windows, not multiple subplots).

using Plots

x = 1:10
plot(x,x, label="linear")
plot(x,x.^2, label="quadratic")

I don’t understand why this code is only creating the last figure. Can you help me?

Thanks

1 Like

Hi and welcome,

have a look at the Plots.jl tutorial. The third and fourth plot on this page explain what you want to do. Basically you want to change your second call to plot into plot! so that it “reuses the existing canvas” and plots the given data into it.

2 Likes

Thanks for your answer. Unfortunately, this is not what I am trying to do. I am trying to create two distinct plots in two distinct figures (maybe “canvas” in your language ;). Basically, I am trying to find the equivalent of figure in Matlab or matplotlib.

Ah sorry, I misunderstood your question. My bad.

So you just want to create two completely separate plots that you can then view inside VSCode, correct? Once you execute your code, a plots pane should open inside the editor showing 2/2. You should be able to switch back and forth between your created plots inside this plots pane.

1 Like

That depends on how you run your code. If you run it in the REPL then display is only called on the last return value, so you get one plot. Try

display(plot(x,x, label="linear"))
display(plot(x,x.^2, label="quadratic"))

or running your code line-by-line instead.

3 Likes

grafik
It should look like this. In the top right corner of this panel you have arrows to switch back and forth between your plot history.
grafik

2 Likes

Thanks. I was indeed executing the file in the RELP. Using display works for me.