# PGFPlotsX.jl - custom color cycler?

**URL:** <https://discourse.julialang.org/t/pgfplotsx-jl-custom-color-cycler/27178>\
**Category:** Visualization\
**Tags:** pgfplotsx\
**Created:** [August 5, 2019, 2:49pm UTC](https://discourse.julialang.org/t/pgfplotsx-jl-custom-color-cycler/27178 "2019-08-05T14:49:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [August 5, 2019, 2:49pm UTC](https://discourse.julialang.org/t/pgfplotsx-jl-custom-color-cycler/27178/1 "2019-08-05T14:49:07Z")

</div>

I am trying to use a custom color cycler for all my plots in my thesis. In my LaTeX style document I defined some colours for testing, here is an example which I found on SO:

```LaTeX
\usepackage{pgfplots}

\definecolor{blues1}{RGB}{198, 219, 239}
\definecolor{blues2}{RGB}{158, 202, 225}
\definecolor{blues3}{RGB}{107, 174, 214}
\definecolor{blues4}{RGB}{49, 130, 189}
\definecolor{blues5}{RGB}{8, 81, 156}

\pgfplotscreateplotcyclelist{colorbrewer-blues}{
{blues1},
{blues2},
{blues3},
{blues4},
{blues5},
}

```

And now I am struggling to get the `cycle list name=colorbrewer-blues` to be passed to the `Axis`. So this is the TeX code :

```LaTeX
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    cycle list name=colorbrewer-blues,
    no markers,
    every axis plot/.append style=thick]
\addplot {rnd*.5-.25};
\addplot {rnd*.5-0.5};
\addplot {rnd*.5-0.75};
\addplot{rnd*.5-1};
\addplot+[orange,very thick]{rnd*.5+x*0.05-0.75};
\end{axis}
\end{tikzpicture}
\end{document}

```

and my non-working code:

```julia
@pgf GroupPlot(
    { group_style = { group_size="2 by 1" },
      no_markers,
      legend_pos="north west",
      xlabel=raw"$\delta$ [deg]",
      cycle=raw"list name=colorbrewer-blues",
    },
    Axis(
        PlotInc(Table(zenith.δ, zenith.λ ./ maximum(zenith.λ))),
        LegendEntry(raw"zenith scan")
        ),
    Axis(
        PlotInc(Table(azimuth.δ, azimuth.λ ./ maximum(azimuth.λ))),
        LegendEntry(raw"azimuth scan"),
        
    )
)

```

PGFPlots of course complains about the bad syntax with

> ! Package pgfkeys Error: I do not know the key ‘/pgfplots/cycle’, to which you  
> passed ‘list name=colorbrewer-blues’, and I am going to ignore it. Perhaps you  
> misspelled it.

Can anyone help? I am still new to both PGFPlotsX.jl and PGFPlots in general, so sorry for this dumb question, I am sure I still did not grasp how both talk to each other 🙈

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [August 5, 2019, 2:51pm UTC](https://discourse.julialang.org/t/pgfplotsx-jl-custom-color-cycler/27178/2 "2019-08-05T14:51:08Z")

</div>

Ahm, it seems `cycle_list=raw"name=colorbrewer-blues"` is the correct one I guess, at least there is no error and everything is grey…

Edit: the corresponding line like this in the TeX output (checked with `print_tex()`), so it’s incorrect since it’s in curly brackets and not in square brackets:

```julia
\begin{groupplot}[group style={group size={2 by 1}}, no markers, legend pos={north west}, xlabel={$\delta$ [deg]}, cycle list={name=colorbrewer-blues}]

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 5, 2019, 3:00pm UTC](https://discourse.julialang.org/t/pgfplotsx-jl-custom-color-cycler/27178/3 "2019-08-05T15:00:19Z")

</div>

> [@tamasgal](#):
>
> cycle=raw"list name=colorbrewer-blues"

Please try

```julia
cycle_list_name = "colorbrewer-blues"

```

or

```julia
"cycle list name" = "colorbrewer-blues"

```

Please look at [the docs](https://kristofferc.github.io/PGFPlotsX.jl/dev/man/options/), starting with “keywords can be entered”.

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [August 5, 2019, 3:02pm UTC](https://discourse.julialang.org/t/pgfplotsx-jl-custom-color-cycler/27178/4 "2019-08-05T15:02:27Z")

</div>

Thanks Tamas. Kind of embarrassingly easy… 😉

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 5, 2019, 3:09pm UTC](https://discourse.julialang.org/t/pgfplotsx-jl-custom-color-cycler/27178/5 "2019-08-05T15:09:02Z")

</div>

No worries. Do you think this is prominent enough in the docs, or we should emphasize it more, eg by giving it its own subsection? It is kind of key to using PGFPlotsX idiomatically.

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [August 5, 2019, 3:13pm UTC](https://discourse.julialang.org/t/pgfplotsx-jl-custom-color-cycler/27178/6 "2019-08-05T15:13:55Z")

</div>

I think it’s prominent enough and it was mainly my blindness/ignorance. I already was on the right track with the `print_tex()` helper function.

The only thing which may have helped to not overlook that is the formatting of the TeX output in the examples. Maybe it’s better to do some nesting instead of the long vertically scrollable lines?

I mean this one (although it might be better to leave the output of `print_tex()` as it is):

```julia
julia> print_tex(a)
\begin{axis}[axis background/.style={shade, top color={gray}, bottom color={white}}, ymode={log}]
    \addplot+[smooth]
        coordinates {
            (1,2)
            (2,4)
            (3,8)
        }
        ;
\end{axis}

```

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [August 5, 2019, 3:24pm UTC](https://discourse.julialang.org/t/pgfplotsx-jl-custom-color-cycler/27178/7 "2019-08-05T15:24:01Z")

</div>

Btw. it’s still somewhat related. I could not figure out a good way to deal with the preamble. Currently I do:

```julia
preamble = split(raw"""
\pgfplotsset{every axis/.append style={
             label style={font=\small},
             tick label style={font=\small}  
             }}
\definecolor{color2}{RGB}{230, 159, 0}
\definecolor{color1}{RGB}{86,180,233}
\definecolor{color3}{RGB}{0,158,115}
\definecolor{color4}{RGB}{240,228,66}
\definecolor{color5}{RGB}{0,114,178}
\definecolor{color6}{RGB}{213,94,0}
\definecolor{color7}{RGB}{204,121,167}

\pgfplotscreateplotcyclelist{colorbrewer-tamasgal}{
{color1},
{color2},
{color3},
{color4},
{color5},
{color6},
{color7}
}
""");

push!(PGFPlotsX.CUSTOM_PREAMBLE, preamble...)

```

I can bury this into an include file but I also found that `PGFPlotsX.CUSTOM_PREAMBLE_PATH` which points to a `custom_preamble.tex` inside the source folder of the package. Is there any way to alter that path? I would like to reuse the same include I use for my thesis in the plotting scripts which produce the plots every time I do a `make` (or run the CI of the thesis-repo).

**Edit: ah damn, forget it. I just found that it can be set via the environment variable `PGFPLOTSX_PREAMBLE_PATH`. I should sleep a few hours I guess 😅**

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 5, 2019, 3:44pm UTC](https://discourse.julialang.org/t/pgfplotsx-jl-custom-color-cycler/27178/8 "2019-08-05T15:44:11Z")

</div>

> [@tamasgal](#):
>
> long vertically scrollable lines?

you mean horizontally? yes, we could do this.

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [August 5, 2019, 3:47pm UTC](https://discourse.julialang.org/t/pgfplotsx-jl-custom-color-cycler/27178/9 "2019-08-05T15:47:54Z")

</div>

Yes, horizontally 😄
