# Plots & PyPlot?

**URL:** <https://discourse.julialang.org/t/plots-pyplot/23510>\
**Category:** General Usage\
**Created:** [April 25, 2019, 1:46pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510 "2019-04-25T13:46:02Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [April 25, 2019, 1:46pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/1 "2019-04-25T13:46:02Z")

</div>

Plots vs. PyPlot seems to have changed…

In the past, the following worked (Julia 1.1.0):

```julia
using Plots
pyplot()

```

This doesn’t work any more – if I do this, I get a lengthy error message:

```julia
┌ Warning: Error requiring PyPlot from Plots:
│ LoadError: MethodError: no method matching getproperty(::PyCall.PyObject, ::String)
│ Closest candidates are:
│ getproperty(::Any, !Matched::Symbol) at sysimg.jl:18
│ Stacktrace:
│ [1] top-level scope at none:0
│ [2] include at .\boot.jl:326 [inlined]
│ [3] include_relative(::Module, ::String) at .\loading.jl:1038
│ [4] include at .\sysimg.jl:29 [inlined]
│ [5] include(::String) at C:\Users\my-user-name\.julia\packages\Plots\47Tik\src\Plots.jl:1
│ [6] top-level scope at none:0
│ [7] eval at .\boot.jl:328 [inlined]
│ [8] eval at C:\Users\my-user-name\.julia\packages\Plots\47Tik\src\Plots.jl:1 [inlined]
│ [9] (::getfield(Plots, Symbol("##294#321")))() at C:\Users\my-user-name\.julia\packages\Requires\9Jse8\src\require.jl:67
│ [10] err(::getfield(Plots, Symbol("##294#321")), ::Module, ::String) at C:\Users\my-user-name\.julia\packages\Requires\9Jse8\src\require.jl:38
│ [11] #293 at C:\Users\my-user-name\.julia\packages\Requires\9Jse8\src\require.jl:66 [inlined]
│ [12] withpath(::getfield(Plots, Symbol("##293#320")), ::String) at C:\Users\my-user-name\.julia\packages\Requires\9Jse8\src\require.jl:28
│ [13] (::getfield(Plots, Symbol("##292#319")))() at C:\Users\my-user-name\.julia\packages\Requires\9Jse8\src\require.jl:65
│ [14] #invokelatest#1 at .\essentials.jl:742 [inlined]
│ [15] invokelatest at .\essentials.jl:741 [inlined]
│ [16] #3 at C:\Users\my-user-name\.julia\packages\Requires\9Jse8\src\require.jl:19 [inlined]
│ [17] iterate at .\generator.jl:47 [inlined]
│ [18] _collect(::Array{Function,1}, ::Base.Generator{Array{Function,1},getfield(Requires, Symbol("##3#4"))}, ::Base.EltypeUnknown, ::Base.HasShape{1}) at .\array.jl:619
│ [19] map at .\array.jl:548 [inlined]
│ [20] loadpkg(::Base.PkgId) at C:\Users\my-user-name\.julia\packages\Requires\9Jse8\src\require.jl:19
│ [21] #invokelatest#1 at .\essentials.jl:742 [inlined]
│ [22] invokelatest at .\essentials.jl:741 [inlined]
│ [23] require(::Base.PkgId) at .\loading.jl:861
│ [24] require(::Module, ::Symbol) at .\loading.jl:853
│ [25] top-level scope at C:\Users\my-user-name\.julia\packages\Plots\47Tik\src\backends.jl:486
│ [26] eval at .\boot.jl:328 [inlined]
│ [27] _initialize_backend(::Plots.PyPlotBackend) at C:\Users\my-user-name\.julia\packages\Plots\47Tik\src\backends.jl:485
│ [28] backend(::Plots.PyPlotBackend) at C:\Users\my-user-name\.julia\packages\Plots\47Tik\src\backends.jl:182
│ [29] #pyplot#253 at C:\Users\my-user-name\.julia\packages\Plots\47Tik\src\backends.jl:33 [inlined]
│ [30] pyplot() at C:\Users\my-user-name\.julia\packages\Plots\47Tik\src\backends.jl:33
│ [31] top-level scope at In[1]:2
│ [32] eval at .\boot.jl:328 [inlined]
│ [33] softscope_include_string(::Module, ::String, ::String) at C:\Users\my-user-name\.julia\packages\SoftGlobalScope\cSbw5\src\SoftGlobalScope.jl:218
│ [34] execute_request(::ZMQ.Socket, ::IJulia.Msg) at C:\Users\my-user-name\.julia\packages\IJulia\gI2uA\src\execute_request.jl:67
│ [35] #invokelatest#1 at .\essentials.jl:742 [inlined]
│ [36] invokelatest at .\essentials.jl:741 [inlined]
│ [37] eventloop(::ZMQ.Socket) at C:\Users\my-user-name\.julia\packages\IJulia\gI2uA\src\eventloop.jl:8
│ [38] (::getfield(IJulia, Symbol("##15#18")))() at .\task.jl:259
│ in expression starting at C:\Users\my-user-name\.julia\packages\Plots\47Tik\src\backends\pyplot.jl:24
└ @ Requires C:\Users\my-user-name\.julia\packages\Requires\9Jse8\src\require.jl:40

```

I have updated `PyPlot`.

If I forget about `pyplot()` and default to `gr()` (i.e., don’t specify the backend), then I avoid the error messages. However, `gr()` produces substandard plots for my use – (i) `gr` doesn’t have complete support for LaTeX, and (ii) it sometimes does something strange wrt. scaling: here is what I try to do…

```julia
using Plots
using LaTeXStrings
# function
f(x,u) = -exp(-1/u)*x^2 + 0.1*exp(-2/u)*x
x = range(0,5,length=25)
u=range(0.01,0.1,length=25)
f3d = plot(u,x,f,st=:surface,c=:blues,colorbar=:none)
plot!(f3d,xlabel=L"u", ylabel=L"c_A",zlabel=L"dc_A/dt")
#plot!(f3d,xlabel=L"u", ylabel=L"c_\mathrm{A}",zlabel=L"\frac{d c_\mathrm{A}}{dt}")
fc =plot(u,x,f,st=:contour,c=:blues)
plot!(fc,xlabel=L"u", ylabel=L"c_A")
#plot!(fc,xlabel=L"u", ylabel=L"c_\mathrm{A}")

plot(f3d,fc,layout=(2,1))

```

I’ve had to comment out things that give error messages with `gr()` – but that should work with `pyplot()`. Even without error messages, `gr()` (i) does not add labels to `f3d`, and (ii) messes up the scaling of `f3d`:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/4/74476999b096cb1d5a4b2cd65213baf20e4a598c.png)

Any ideas on how to fix this? Have I done anything wrong?

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [April 25, 2019, 4:15pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/2 "2019-04-25T16:15:42Z")

</div>

The point is, that `\mathrm` is not defined in the LaTeX prologue using within GR. I’ll see how this can be fixed …

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [April 25, 2019, 4:28pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/3 "2019-04-25T16:28:38Z")

</div>

Thanks, Josef. Although PyPlot is still more complete, I notice that GR produces a “crisper” / “cleaner” plot, which is nice.

Notice: in addition to “\mathrm”, I think there was also a problem with ,“\frac”.

Btw: any idea why the 3D surface plot doesn’t rescale when stacked with the contour plot?

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [April 25, 2019, 5:39pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/4 "2019-04-25T17:39:36Z")

</div>

You need to `]up PyPlot`.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [April 25, 2019, 6:09pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/5 "2019-04-25T18:09:42Z")

</div>

What is `]up PyPlot`? Update? (I probably should know this, but I use `using Pkg` and `Pkg.update("PyPlot")`… reason: this can be put in a file together with other commands and run as script file…)

Note: I _did_ update PyPlot before I submitted the question, with no effect.

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [April 25, 2019, 8:04pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/6 "2019-04-25T20:04:57Z")

</div>

I gave your code a try, but inserted `pyplot()` after `using...`. It works well on my win10 machine, Julia 1.10, latest Plots&PyPlot.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [April 25, 2019, 8:17pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/7 "2019-04-25T20:17:21Z")

</div>

Weird.

Some 1-2 month ago, there was also a problem with Plots and PyPlot. I was then adviced to “lock” PyPlot (?) to an older, working version. Don’t recall the command… after that, I uninstalled and reinstalled PyPlot…

Could it be that that “lock” persists? If so, what is the command for removing such a “lock” to a specific version?

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [April 25, 2019, 8:30pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/8 "2019-04-25T20:30:06Z")

</div>

`] free PyPlot` perhaps?

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [April 25, 2019, 9:20pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/9 "2019-04-25T21:20:16Z")

</div>

Thanks! I just checked again 30 minutes ago, doing `] status`, and found a suspicious symbol next to `PyPlot` and `PyCall` … something that looked like a key. So I dug around in the documentation, and found precisely the `] free` command (actually, not in the manual, but in the REPL/package manager).

When freeing the too packages, and running `update`, it seems like `PyCall` gets updated from v. 1.18.5 to v. 1.91.2, while `PyPlot` gets updated from v. 2.7.0 to v. 2.8.1.

“Seems like” in the sense that it takes “forever” to do the update… it’s still running.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [April 25, 2019, 9:30pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/10 "2019-04-25T21:30:27Z")

</div>

Yes! Thanks! It works…

Only one thing:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/f/bf2be4c50d60e9d45a77702d68e6a93e5bb1e9d1.jpeg)

Why do I get this warning? Why are the “rainbow” colors defined two places? This error message does not show up if I use `c = :blues` or `c= :grays`…

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [April 25, 2019, 10:36pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/11 "2019-04-25T22:36:33Z")

</div>

That’s something to watch out for in PlotUtils. Since a miscellaneous set of colours (`misc`) was added for testing and giggles, and the ‘default’ library with which to handle this hasn’t been defined by you, PlotUtils will show a warning. You can squelch this by including the statement `uselibrary(:misc)` or `uselibrary(:colorcet)` somewhere above it.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [April 26, 2019, 7:25am UTC](https://discourse.julialang.org/t/plots-pyplot/23510/12 "2019-04-26T07:25:40Z")

</div>

Thanks. But you do not say _where_ to include the statement `uselibrary(:misc)`. I tried to include it in my Julia code, _after_ I have done `using Plots`, and then I get an error message:

```julia
UndefVarError: uselibrary not defined

Stacktrace:
 [1] top-level scope at In[3]:2

```

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [April 26, 2019, 9:20am UTC](https://discourse.julialang.org/t/plots-pyplot/23510/13 "2019-04-26T09:20:14Z")

</div>

Shit, wrong function 🙂 it’s actually `clibrary`, sorry about that!

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [April 26, 2019, 1:13pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/14 "2019-04-26T13:13:45Z")

</div>

Yup! `clibrary(:colorcet)` works! Thanks!

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [April 26, 2019, 1:56pm UTC](https://discourse.julialang.org/t/plots-pyplot/23510/15 "2019-04-26T13:56:54Z")

</div>

…and now I get a strange warning for a contour plot…

```julia
fc =plot(x,u,f,st=:contour,c=:rainbow)
plot!(fc,ylabel=L"u", xlabel=L"c_\mathrm{A}")

```

leads to the plot:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/e/2e1bafa2880519c16b6eb9751582a597270fdb21.jpeg)  
and the warning:

```julia
C:\Users\user_name\.julia\conda\3\lib\site-packages\matplotlib\contour.py:1000: UserWarning: The following kwargs were not used by contour: 'label'
  s)

```

Am I supposed to use a label? What is the label? The z-value??

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [April 27, 2019, 2:28am UTC](https://discourse.julialang.org/t/plots-pyplot/23510/16 "2019-04-27T02:28:41Z")

</div>

That might just be a matplotlib/pyplot thing - I don’t even know if Plots supports contour labels…

Have you tried using the GR backend?
