# Switch between PyPlot and Plots

**URL:** <https://discourse.julialang.org/t/switch-between-pyplot-and-plots/5304>\
**Category:** New to Julia\
**Created:** [August 9, 2017, 2:34pm UTC](https://discourse.julialang.org/t/switch-between-pyplot-and-plots/5304 "2017-08-09T14:34:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)\
**Post date:** [August 9, 2017, 2:34pm UTC](https://discourse.julialang.org/t/switch-between-pyplot-and-plots/5304/1 "2017-08-09T14:34:56Z")

</div>

I found the following example in julialang regarding switching between backends:

````julia
#Pkg.add("Plots")
using Plots
plotly() # Choose the Plotly.jl backend for web interactivity
plot(rand(5,5),linewidth=2,title="My Plot")
#Pkg.add("PyPlot") # Install a different backend
pyplot() # Switch to using the PyPlot.jl backend
plot(rand(5,5),linewidth=2,title="My Plot2") # The same plotting command works``` 

````

But I have 2 problems when I run this code:

1. I only see the second plot, and not the first one when I run the entire code. How can I see both plots at the same time?

2. I’d like to have `using PyPlot ion()` in my juliarc to get the figures in another window. But when I have this I get the following error message:

```julia
WARNING: both Plots and PyPlot export "plot"; uses of it in module Main must be qualified

UndefVarError: plot not defined

```

can I solve this somehow so I can still include that in my juliarc.jl?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 9, 2017, 3:37pm UTC](https://discourse.julialang.org/t/switch-between-pyplot-and-plots/5304/2 "2017-08-09T15:37:30Z")

</div>

Check out the Plots.jl Tutorial

[https://juliaplots.github.io/tutorial/](https://juliaplots.github.io/tutorial/)

> [@nako95](#):
>
> I only see the second plot, and not the first one when I run the entire code. How can I see both plots at the same time?

`display(plot(...))`. It’s explained in the tutorial.

> [@nako95](#):
>
> I’d like to have using PyPlot ion() in my juliarc to get the figures in another window. But when I have this I get the following error message:

This is because both package export `plot`. I would suggest doing `import PyPlot` instead, and then do `PyPlot.plot(...)` and `Plots.plot(...)`. Or you can just use the Plots.jl PyPlot backend.

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [August 9, 2017, 4:18pm UTC](https://discourse.julialang.org/t/switch-between-pyplot-and-plots/5304/3 "2017-08-09T16:18:28Z")

</div>

If you would like to display the two plots in the same window, you should call the `plot!()` function, with the exclamation mark: this modifies the first plot.  
If instead you would like to plot the second graph in a new window, you call `plot(..., reuse=false)`.

---

<div class="post-metadata">

**Author:** ![nako95](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nako95](https://discourse.julialang.org/u/nako95)\
**Post date:** [August 10, 2017, 7:17am UTC](https://discourse.julialang.org/t/switch-between-pyplot-and-plots/5304/4 "2017-08-10T07:17:00Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 10, 2017, 8:04am UTC](https://discourse.julialang.org/t/switch-between-pyplot-and-plots/5304/5 "2017-08-10T08:04:37Z")

</div>

1. You cannot show plots generated by different backends in the same window.
2. @nako95 , could you edit the title to “Switch between pyplot and plotly backends for Plots”? You are not shifting between PyPlot and Plots - those two packages cannot be loaded simultaneously, as they both define `plot`.  
Also, loading PyPlot and calling the `ion()` function in the juliarc file will affect PyPlot behavior, but should not affect the behaviour of Plots. You can’t mix-and-match Plots and PyPlot functionality.
