# How to configure a colormap using PyPlot

**URL:** <https://discourse.julialang.org/t/how-to-configure-a-colormap-using-pyplot/43746>\
**Category:** New to Julia\
**Tags:** question, plotting, pyplot\
**Created:** [July 27, 2020, 7:42am UTC](https://discourse.julialang.org/t/how-to-configure-a-colormap-using-pyplot/43746 "2020-07-27T07:42:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roi.holtzman](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)\
**Post date:** [July 27, 2020, 7:42am UTC](https://discourse.julialang.org/t/how-to-configure-a-colormap-using-pyplot/43746/1 "2020-07-27T07:42:18Z")

</div>

I am trying to set the default colormap using PyPlot, but the colors are still the default colors.

Here’s a MWE

```julia
using PyPlot

PyPlot.matplotlib.rc("image",cmap="gray")

fig, ax = subplots()

x = 1:0.1:10
y = exp.(x/π)

ax.plot(x/π,y, "-o")

```

and the plot is  
 ![example_pyplot](https://global.discourse-cdn.com/julialang/original/3X/4/b/4b06741020471dec18cab829c72bcf5b54e8097a.png)

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![fgerick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fgerick/32/13228_2.png) [@fgerick](https://discourse.julialang.org/u/fgerick)\
**Post date:** [July 27, 2020, 7:58am UTC](https://discourse.julialang.org/t/how-to-configure-a-colormap-using-pyplot/43746/2 "2020-07-27T07:58:40Z")

</div>

Not sure this is what you want, but you can do this:

```julia
cm = get_cmap(:gray)

fig, ax = subplots()

x = 1:0.1:10
y = exp.(x/π)

ax.plot(x/π,y, "-o",color=cm(0.0))
ax.plot(x/π,2y, "-o",color=cm(0.4))
ax.plot(x/π,3y, "-o",color=cm(0.9))

```

The values to get the color need to be either floats between `0.0` and `1.0` or `Int` between `0` and `255`.

---

<div class="post-metadata">

**Author:** ![roi.holtzman](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)\
**Post date:** [July 27, 2020, 8:15am UTC](https://discourse.julialang.org/t/how-to-configure-a-colormap-using-pyplot/43746/3 "2020-07-27T08:15:32Z")

</div>

Actually, my intent is to use by default 20 different colors to plot 20 different data sets.  
I thought of using `tab20` color map (see [here](https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html)).

I know that I can simply do this

```julia
cm = get_cmap(:tab20)

fig, ax = subplots()

x = 1:0.1:10
y = exp.(x/π)
colorrange = (0:19) ./ 20
for i=1:20
    ax.plot(x/π,i*y, "-o",color=cm(colorrange[i]))
end

```

and get  
 ![pyplot_colormap_example](https://global.discourse-cdn.com/julialang/original/3X/6/4/6481830daabdf5db816798d29b08d961fbc69d51.png)

But I was wondering if there is a way to simply set the default color set, and let all the colors be chosen by order from this set.

---

<div class="post-metadata">

**Author:** ![fgerick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fgerick/32/13228_2.png) [@fgerick](https://discourse.julialang.org/u/fgerick)\
**Post date:** [July 27, 2020, 11:36am UTC](https://discourse.julialang.org/t/how-to-configure-a-colormap-using-pyplot/43746/4 "2020-07-27T11:36:21Z")

</div>

I see. I found a way to do this from [this page of the manual](https://matplotlib.org/3.2.1/tutorials/intermediate/color_cycle.html) I followed this solution:

```julia

using PyPlot

using PyCall

cm=get_cmap(:tab20);

cycler = pyimport("cycler")
PyPlot.rc("axes",prop_cycle=cycler.cycler(color=[cm(t/19) for t in 0:19]))

fig, ax = subplots()

x = 1:0.1:10
y = exp.(x/π)

for i=1:20
    ax.plot(x/π,i*y, "-o")
end

```

which gives the plot you have shown above! Probably there’s a nicer way to extract the `tab20` cycler!?
