# Color gradient doesn't work

**URL:** <https://discourse.julialang.org/t/color-gradient-doesnt-work/111734>\
**Category:** General Usage\
**Tags:** colors, python, plot, pythonplot\
**Created:** [March 17, 2024, 9:10pm UTC](https://discourse.julialang.org/t/color-gradient-doesnt-work/111734 "2024-03-17T21:10:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [March 17, 2024, 9:10pm UTC](https://discourse.julialang.org/t/color-gradient-doesnt-work/111734/1 "2024-03-17T21:10:37Z")

</div>

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:

```julia
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

```

---

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [March 17, 2024, 9:19pm UTC](https://discourse.julialang.org/t/color-gradient-doesnt-work/111734/2 "2024-03-17T21:19:10Z")

</div>

Palette is not a keyword arg see  
[https://matplotlib.org/2.0.2/api/\_as\_gen/matplotlib.axes.Axes.plot.html](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/](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.

---

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [March 17, 2024, 10:59pm UTC](https://discourse.julialang.org/t/color-gradient-doesnt-work/111734/3 "2024-03-17T22:59:15Z")

</div>

I’m specifically trying to do this:

> [@Plots.jl: Assigning seriescolor using ColorGradient for line plot](https://discourse.julialang.org/t/plots-jl-assigning-seriescolor-using-colorgradient-for-line-plot/17099/9):
>
> Eh, plot(X, palette = :inferno) is already valid Plots syntax? Note that Plots cannot know how many series you will add in the future, so when specifying a palette it will always try to select each color to be as widely spaced on the color gradient as possible. If you know you have 5 series and want them spaced on the color gradient sequentially, you can use color and spread line\_z over the 5 series: plot(rand(20,5), color = :RdYlBu, line\_z = (1:5)') You can also just supply a …

---

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [March 18, 2024, 4:41am UTC](https://discourse.julialang.org/t/color-gradient-doesnt-work/111734/4 "2024-03-18T04:41:33Z")

</div>

```julia
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.

---

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [March 18, 2024, 10:33am UTC](https://discourse.julialang.org/t/color-gradient-doesnt-work/111734/5 "2024-03-18T10:33:27Z")

</div>

I’m tryng to write this:

```julia
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.

---

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [March 18, 2024, 11:18am UTC](https://discourse.julialang.org/t/color-gradient-doesnt-work/111734/6 "2024-03-18T11:18:55Z")

</div>

I found this : No need for ColorSchemes here

```julia
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

```julia
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 …

---

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [March 21, 2024, 9:39pm UTC](https://discourse.julialang.org/t/color-gradient-doesnt-work/111734/7 "2024-03-21T21:39:50Z")

</div>

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

Thanks it works.  
hopefully no strange x gradient, ahahah
