# Plotting multiple figures using Plots.jl

**URL:** <https://discourse.julialang.org/t/plotting-multiple-figures-using-plots-jl/57859>\
**Category:** Visualization\
**Tags:** plotting, vscode\
**Created:** [March 24, 2021, 10:54am UTC](https://discourse.julialang.org/t/plotting-multiple-figures-using-plots-jl/57859 "2021-03-24T10:54:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marca85](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@Marca85](https://discourse.julialang.org/u/Marca85)\
**Post date:** [March 24, 2021, 10:54am UTC](https://discourse.julialang.org/t/plotting-multiple-figures-using-plots-jl/57859/1 "2021-03-24T10:54:17Z")

</div>

Hi,

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

```julia
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

---

<div class="post-metadata">

**Author:** ![fbanning](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fbanning/32/14972_2.png) [@fbanning](https://discourse.julialang.org/u/fbanning)\
**Post date:** [March 24, 2021, 11:02am UTC](https://discourse.julialang.org/t/plotting-multiple-figures-using-plots-jl/57859/2 "2021-03-24T11:02:05Z")

</div>

Hi and welcome,

have a look at the [Plots.jl tutorial](https://docs.juliaplots.org/latest/tutorial/#Basic-Plotting:-Line-Plots). 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.

---

<div class="post-metadata">

**Author:** ![Marca85](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@Marca85](https://discourse.julialang.org/u/Marca85)\
**Post date:** [March 24, 2021, 11:07am UTC](https://discourse.julialang.org/t/plotting-multiple-figures-using-plots-jl/57859/3 "2021-03-24T11:07:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fbanning](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fbanning/32/14972_2.png) [@fbanning](https://discourse.julialang.org/u/fbanning)\
**Post date:** [March 24, 2021, 11:18am UTC](https://discourse.julialang.org/t/plotting-multiple-figures-using-plots-jl/57859/4 "2021-03-24T11:18:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [March 24, 2021, 11:20am UTC](https://discourse.julialang.org/t/plotting-multiple-figures-using-plots-jl/57859/5 "2021-03-24T11:20:03Z")

</div>

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

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

```

or running your code line-by-line instead.

---

<div class="post-metadata">

**Author:** ![fbanning](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fbanning/32/14972_2.png) [@fbanning](https://discourse.julialang.org/u/fbanning)\
**Post date:** [March 24, 2021, 11:21am UTC](https://discourse.julialang.org/t/plotting-multiple-figures-using-plots-jl/57859/6 "2021-03-24T11:21:40Z")

</div>

> [@fbanning](#):
>
> a plots pane should open inside the editor showing `2/2` .

![grafik](https://global.discourse-cdn.com/julialang/original/3X/e/5/e5684e11ff60d0be3489f6dc2499aaf02ac802dd.png)  
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](https://global.discourse-cdn.com/julialang/original/3X/5/4/54e17122f15b60deec46983e834f4ceface90f78.png)

---

<div class="post-metadata">

**Author:** ![Marca85](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@Marca85](https://discourse.julialang.org/u/Marca85)\
**Post date:** [March 24, 2021, 1:39pm UTC](https://discourse.julialang.org/t/plotting-multiple-figures-using-plots-jl/57859/7 "2021-03-24T13:39:46Z")

</div>

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