# Problem with contour plots in PythonPlot.jl

**URL:** <https://discourse.julialang.org/t/problem-with-contour-plots-in-pythonplot-jl/118435>\
**Category:** Visualization\
**Tags:** plots, pythonplot, contouring\
**Created:** [August 21, 2024, 3:27am UTC](https://discourse.julialang.org/t/problem-with-contour-plots-in-pythonplot-jl/118435 "2024-08-21T03:27:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sh\_166](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sh_166/32/43965_2.png) [@Sh\_166](https://discourse.julialang.org/u/Sh_166)\
**Post date:** [August 21, 2024, 3:27am UTC](https://discourse.julialang.org/t/problem-with-contour-plots-in-pythonplot-jl/118435/1 "2024-08-21T03:27:19Z")

</div>

With reference to my earlier post [here](https://discourse.julialang.org/t/set-a-minimum-level-in-contour-plots/117907), I have stumbled upon a bad issue.

As in the earlier post, my code is as follows:

```julia
using PythonPlot, LaTeXStrings, Measures, PlotThemes

f(X, Y) = (100/(3*s*k^2))*(((1-(X/Y)^2)^3))*(Y^4)

mₕ, v, mₜ, Nₜ = 125, 246, 172.76, 3
k= pi*mₕ*v
s = 1 - (Nₜ/(3*k^2))mₜ^4
X, Y = range(0, 200, 1000), range(0, 500, 2000)
Z = @. f(X', Y)
zc = [4.2, 5, 10, 30, 70, 100]

contour(X, Y, Z, levels=zc, lw=1, color = :turbo, clims=extrema(zc), cbar = false, clabels = true, framestyle = :box, fontfamily = "cmr10",
        ylims = (150, 480), xlabel = "M [GeV]", ylabel = L"$m_{\Phi}$ [GeV]", title = L"\Delta \lambda/ \lambda^{SM}_{hhh}\ (\%)")

```

The output I was getting earlier is:  
 ![Screenshot 2024-08-21 122157](https://global.discourse-cdn.com/julialang/original/3X/4/f/4f36e9e3c59b3ba57585c54a0771eff3c81a9fe7.jpeg)

However, I was running the code again after adding an additional point for z=4.2. The code is the same - the output this time is:

 ![Screenshot 2024-08-21 122314](https://global.discourse-cdn.com/julialang/original/3X/1/5/155e919a5d0116919f986eb07c9caecfa89b8ffa.jpeg)

I don’t understand this at all - the code seems to completely ignore the labels, titles, axes, everything.

Moreover, if I import `PlotThemes.jl` and run `theme(:bright)`, the statement shoots up an error:

```julia
UndefVarError: `theme` not defined

```

Can anyone help me with this? It really doesn’t matter to me if the solution is not based in PythonPlot at all - I just want to create the figure.

EDIT:  
Sometimes I get the warning:

```julia
sys:1: UserWarning: The following kwargs were not used by contour: 'lw', 'color', 'clims', 'cbar', 'clabels', 'framestyle', 'fontfamily', 'ylims', 'xlabel', 'ylabel', 'title'

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 21, 2024, 6:32pm UTC](https://discourse.julialang.org/t/problem-with-contour-plots-in-pythonplot-jl/118435/2 "2024-08-21T18:32:59Z")

</div>

You seem to be mixing Plots.jl with PythonPlot.jl code.  
Using Plots.jl’s pythonplot() backend, your example runs just fine.

> **Plots.jl pythonplot() code**
>
> ```julia
> using LaTeXStrings, Measures, Plots
> pythonplot(dpi=100)
> 
> f(X, Y) = (100/(3*s*k^2))*(((1-(X/Y)^2)^3))*(Y^4)
> 
> mₕ, v, mₜ, Nₜ = 125, 246, 172.76, 3
> k= pi*mₕ*v
> s = 1 - (Nₜ/(3*k^2))mₜ^4
> X, Y = range(0, 200, 1000), range(0, 500, 2000)
> Z = @. f(X', Y)
> zc = [4.2, 5, 10, 30, 70, 100]
> 
> theme(:bright)
> contour(X, Y, Z, levels=zc, lw=1, color=:turbo, clims=extrema(zc), cbar=false, clabels=true, framestyle=:box, fontfamily="cmr10",
> ylims=(150, 480), xlabel="M [GeV]", ylabel=L"$m_{\Phi}$ [GeV]", title=L"\Delta \lambda/ \lambda^{SM}_{hhh}\ (\%)")
> 
> ```

---

<div class="post-metadata">

**Author:** ![Sh\_166](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sh_166/32/43965_2.png) [@Sh\_166](https://discourse.julialang.org/u/Sh_166)\
**Post date:** [August 22, 2024, 1:01am UTC](https://discourse.julialang.org/t/problem-with-contour-plots-in-pythonplot-jl/118435/3 "2024-08-22T01:01:33Z")

</div>

Yes, well, that is the problem - for some reason, parts of this code don’t seem to run. The `theme` part, for example.

I stopped importing `PythonPlot.jl` and ran the code entirely with `Plots.jl` with the default backend. Turns out that works almost perfectly except for the fact that the contour labels (5, 10, 30, 70, 100) are written twice on their corresponding contour lines. In the end, I switched off the label and printed the contour plot and added the labels by hand.
