Shade area under curve with pyplot backend

Hi,

I would like to shade the area under a curve with the pyplot backend in Plots.jl. The code works for the GR backend, but not the pyplot backend. Is this a bug or does pyplot require different syntax?

using Plots, Distributions

pyplot()

x = range(-3, 3, length=100)
y = pdf.(Normal(0,1), x)

ix = abs.(x) .< 1
plot(x[ix], y[ix], fillrange = zero(x[ix]), fc=:blues)
plot!(x, y, grid=false, lc=:black, widen=false)

Error

Summary
ERROR: MethodError: no method matching py_color(::PlotUtils.ContinuousColorGradient, ::Nothing)

Closest candidates are:
  py_color(::PlotUtils.AbstractColorList)
   @ Plots ~/.julia/packages/Plots/sxUvK/src/backends/deprecated/pyplot.jl:75
  py_color(::Colorant, ::Any)
   @ Plots ~/.julia/packages/Plots/sxUvK/src/backends/deprecated/pyplot.jl:76
  py_color(::Any)
   @ Plots ~/.julia/packages/Plots/sxUvK/src/backends/deprecated/pyplot.jl:72

Stacktrace:
  [1] py_add_series(plt::Plots.Plot{Plots.PyPlotBackend}, series::Plots.Series)
    @ Plots ~/.julia/packages/Plots/sxUvK/src/backends/deprecated/pyplot.jl:806
  [2] #693
    @ ~/.julia/packages/Plots/sxUvK/src/backends/deprecated/pyplot.jl:946 [inlined]
  [3] foreach
    @ ./abstractarray.jl:3075 [inlined]
  [4] _before_layout_calcs(plt::Plots.Plot{Plots.PyPlotBackend})
    @ Plots ~/.julia/packages/Plots/sxUvK/src/backends/deprecated/pyplot.jl:946
  [5] prepare_output(plt::Plots.Plot{Plots.PyPlotBackend})
    @ Plots ~/.julia/packages/Plots/sxUvK/src/plot.jl:232
  [6] show
    @ ~/.julia/packages/Plots/sxUvK/src/output.jl:231 [inlined]
  [7] __binrepr(m::MIME{Symbol("image/svg+xml")}, x::Plots.Plot{Plots.PyPlotBackend}, context::Nothing)
    @ Base.Multimedia ./multimedia.jl:171
  [8] _textrepr
    @ ./multimedia.jl:163 [inlined]
  [9] #stringmime#8
    @ ~/julia-1.9.3/share/julia/stdlib/v1.9/Base64/src/Base64.jl:44 [inlined]
 [10] stringmime
    @ ~/julia-1.9.3/share/julia/stdlib/v1.9/Base64/src/Base64.jl:44 [inlined]
 [11] display(d::VSCodeServer.InlineDisplay, m::MIME{Symbol("image/svg+xml")}, x::Plots.Plot{Plots.PyPlotBackend})
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.54.2/scripts/packages/VSCodeServer/src/display.jl:62
 [12] display(d::VSCodeServer.InlineDisplay, mime::String, x::Any)
    @ Base.Multimedia ./multimedia.jl:228
 [13] display(d::VSCodeServer.InlineDisplay, x::Plots.Plot{Plots.PyPlotBackend})
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.54.2/scripts/packages/VSCodeServer/src/display.jl:198
 [14] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [15] #invokelatest#2
    @ ./essentials.jl:819 [inlined]
 [16] invokelatest
    @ ./essentials.jl:816 [inlined]
 [17] (::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.54.2/scripts/packages/VSCodeServer/src/eval.jl:227
 [18] withpath(f::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.54.2/scripts/packages/VSCodeServer/src/repl.jl:274
 [19] (::VSCodeServer.var"#66#71"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.54.2/scripts/packages/VSCodeServer/src/eval.jl:179
 [20] hideprompt(f::VSCodeServer.var"#66#71"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.54.2/scripts/packages/VSCodeServer/src/repl.jl:38
 [21] (::VSCodeServer.var"#65#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.54.2/scripts/packages/VSCodeServer/src/eval.jl:150
 [22] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging ./logging.jl:514
 [23] with_logger
    @ ./logging.jl:626 [inlined]
 [24] (::VSCodeServer.var"#64#69"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.54.2/scripts/packages/VSCodeServer/src/eval.jl:253
 [25] #invokelatest#2
    @ ./essentials.jl:819 [inlined]
 [26] invokelatest(::Any)
    @ Base ./essentials.jl:816
 [27] macro expansion
    @ ~/.vscode/extensions/julialang.language-julia-1.54.2/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
 [28] (::VSCodeServer.var"#62#63")()
    @ VSCodeServer ./task.jl:514

Does this produce the desired result?

Plots.plot(x[ix], y[ix], fill=(0, :lightblue))
Plots.plot!(x, y, grid=false, lc=:black, widen=false)

image

1 Like

That does. Thanks!