Color gradient doesn't work

I have a for loop. I want the color used to be evenly spaced from a color gradient such as inferno. I read various stuff online, but none works.

for example trying the palette = : inferno in ax.plot of pythonplot gives:

ERROR: LoadError: Python: AttributeError: Line2D.set() got an unexpected keyword argument 'palette'
Python stacktrace:
 [1] _update_props
   @ matplotlib.artist ~/.julia/environments/v1.10/.CondaPkg/env/lib/python3.12/site-packages/matplotlib/artist.py:1193
 [2] _internal_update
   @ matplotlib.artist ~/.julia/environments/v1.10/.CondaPkg/env/lib/python3.12/site-packages/matplotlib/artist.py:1219
 [3] __init__
   @ matplotlib.lines ~/.julia/environments/v1.10/.CondaPkg/env/lib/python3.12/site-packages/matplotlib/lines.py:407
 [4] _makeline
   @ matplotlib.axes._base ~/.julia/environments/v1.10/.CondaPkg/env/lib/python3.12/site-packages/matplotlib/axes/_base.py:346
 [5] <genexpr>
   @ matplotlib.axes._base ~/.julia/environments/v1.10/.CondaPkg/env/lib/python3.12/site-packages/matplotlib/axes/_base.py:532
 [6] _plot_args
   @ matplotlib.axes._base ~/.julia/environments/v1.10/.CondaPkg/env/lib/python3.12/site-packages/matplotlib/axes/_base.py:539
 [7] __call__
   @ matplotlib.axes._base ~/.julia/environments/v1.10/.CondaPkg/env/lib/python3.12/site-packages/matplotlib/axes/_base.py:303
 [8] plot
   @ matplotlib.axes._axes ~/.julia/environments/v1.10/.CondaPkg/env/lib/python3.12/site-packages/matplotlib/axes/_axes.py:1724
Stacktrace:
 [1] pythrow()
   @ PythonCall ~/.julia/packages/PythonCall/wXfah/src/err.jl:94
 [2] errcheck
   @ ~/.julia/packages/PythonCall/wXfah/src/err.jl:10 [inlined]
 [3] pycallargs(f::PythonCall.Py, args::PythonCall.Py, kwargs::PythonCall.Py)
   @ PythonCall ~/.julia/packages/PythonCall/wXfah/src/abstract/object.jl:211
 [4] pycall(::PythonCall.Py, ::Vector{…}, ::Vararg{…}; kwargs::@Kwargs{…})
   @ PythonCall ~/.julia/packages/PythonCall/wXfah/src/abstract/object.jl:222
 [5] (::PythonCall.Py)(::Vector{Int64}, ::Vararg{Any}; kwargs::@Kwargs{markersize::Int64, label::String, palette::Symbol})
   @ PythonCall ~/.julia/packages/PythonCall/wXfah/src/Py.jl:341
 [6] top-level scope
   @ ~/Desktop/Programmi/MODULO_05/executable_and_libraries/bin/read8.jl:71
 [7] include(fname::String)
   @ Base.MainInclude ./client.jl:489
 [8] top-level scope
   @ REPL[1]:1

Palette is not a keyword arg see
https://matplotlib.org/2.0.2/api/_as_gen/matplotlib.axes.Axes.plot.html

Maybe there will be something good for you I don’t know it enough

Maybe in julia with
https://docs.juliaplots.org/latest/generated/colorschemes/

Ps : an mwe or your exact program (if not too long) would be far easier for us to help you.

1 Like

I’m specifically trying to do this:

Using Plots, ColorSchemes

plot(X, palette=:inferno)

Don’t forget to add ColorSchemes.

Looking at the error I feel like you tried to use PythonCall to call matplotlib that’s why I would like your code or a piece of it I know what you are trying to do but the error makes me think you’re not using the standard Plots package of Julia.

I’m tryng to write this:

using PythonPlot
using ColorSchemes

x = [1, 2]
y = Float64[0.8, 0.9, 1.01, 1.02, 1.03, 1.04]
fig1 = pyplot.figure()
ax1 = fig1.add_subplot(1, 1, 1)

for i = 0:2
    ax1.plot(x, y[1+i:2+i], palette = :ColorSchemes.inferno)
end

But it doesn’t work

I specifically need PythonPlot as all non-python plots round to float32 stuff and i need oscillations in float64 digits.

I found this : No need for ColorSchemes here

julia> x = [1, 2]
2-element Vector{Int64}:
 1
 2

julia> y = Float64[0.8, 0.9, 1.01, 1.02, 1.03, 1.04]
6-element Vector{Float64}:
 0.8
 0.9
 1.01
 1.02
 1.03
 1.04

julia> fig1 = pyplot.figure()
Python: <Figure size 640x480 with 0 Axes>

julia> ax1 = fig1.add_subplot(1, 1, 1)
Python: <Axes: >

julia> color = get_cmap("viridis")
ColorMap "viridis"

julia> for i = 0:2
           ax1.plot(x, y[1+i:2+i], color = color(i*100))
           end
julia>

otherwise the typical way to do it is

for i = 0:2
           ax1.plot(x, y[1+i:2+i], color = (1.0,0.0,0.0,1.0))
           end

Please tell me you don’t want the color to be going with x axes …

1 Like

Sorry for the late reply, but here i am now.

Thanks it works.
hopefully no strange x gradient, ahahah

1 Like