# Color cycling in GLMakie.series

**URL:** <https://discourse.julialang.org/t/color-cycling-in-glmakie-series/100834>\
**Category:** Visualization\
**Tags:** makie, glmakie\
**Created:** [June 26, 2023, 9:48am UTC](https://discourse.julialang.org/t/color-cycling-in-glmakie-series/100834 "2023-06-26T09:48:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)\
**Post date:** [June 26, 2023, 9:48am UTC](https://discourse.julialang.org/t/color-cycling-in-glmakie-series/100834/1 "2023-06-26T09:48:34Z")

</div>

I’ve only just discovered `series` in GLMakie as a simple way of plotting rows of a matrix. This is something I do a lot (actually, I’d prefer to plot columns, but never mind) but it doesn’t seem to like plotting more series than there are colours in the scheme.

E.g., `series(rand(7,100)` is fine, but `series(rand(8,100))` results in

```julia
ERROR: Not enough colors for number of categories. Categories: 8, colors: 7

```

Is there an easy way to get series to cycle through `colors` rather than give up if there are too many rows in the matrix?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [June 26, 2023, 9:55am UTC](https://discourse.julialang.org/t/color-cycling-in-glmakie-series/100834/2 "2023-06-26T09:55:29Z")

</div>

This happens because we chose a colormap which looks good, but doesn’t have infinite colors for infinite categories, so at some point it must error that it doesn’t have enough colors.  
Categorical colors are somewhat hard for large amounts of categories, since one still wants them to be maximally distinguishable, while looking nice!

You can pass `color=colormap_with_enough_colors`. Easiest way to achieve this would be `color=rand(RGBf, 8)`, but that isn’t guaranteed to look good nor be maximally distinguishable.  
If anyone has a good idea how to not error and more nicely scale up distinguishable colors that look good beyond 7 colors, please open an issue / pr 🙂  
I initially experimented with [Colormaps and Colorscales · Colors](https://juliagraphics.github.io/Colors.jl/stable/colormapsandcolorscales/#Generating-distinguishable-colors), but wasn’t too happy with the look of that. But maybe worth giving it another try.

---

<div class="post-metadata">

**Author:** ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)\
**Post date:** [June 26, 2023, 10:01am UTC](https://discourse.julialang.org/t/color-cycling-in-glmakie-series/100834/3 "2023-06-26T10:01:20Z")

</div>

Fair enough but is there a reason not to just cycle through the colormap (maybe optionally) like repeated calls to `lines!` does?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [June 26, 2023, 10:23am UTC](https://discourse.julialang.org/t/color-cycling-in-glmakie-series/100834/4 "2023-06-26T10:23:27Z")

</div>

Yes, because then you map multiple lines to the same color, which can be pretty dangerous if the user is unaware of this - for cycling with single line calls, this seems fine to me, but a single call to series mapping multiple lines to one color sounds to me like a setup for subtle bugs…

---

<div class="post-metadata">

**Author:** ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)\
**Post date:** [June 26, 2023, 10:31am UTC](https://discourse.julialang.org/t/color-cycling-in-glmakie-series/100834/5 "2023-06-26T10:31:09Z")

</div>

Thanks for your help - understood. I used to use Matlab a lot and that would plot the columns of a matrix by default iirc, which was quite convenient for the sorts of things I’m doing (dealing with data from a 64-channel sensor), but your reasoning is equally valid.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [June 26, 2023, 10:39am UTC](https://discourse.julialang.org/t/color-cycling-in-glmakie-series/100834/6 "2023-06-26T10:39:15Z")

</div>

Were they cycling, or did they have better ways to generate 64 distinguishable colors?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [June 26, 2023, 10:42am UTC](https://discourse.julialang.org/t/color-cycling-in-glmakie-series/100834/7 "2023-06-26T10:42:31Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/e/e/eefae2656b63517c107e9af61b4702ffdd56c68b.jpeg)

matplotlib definitly cycles after a certain point

---

<div class="post-metadata">

**Author:** ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)\
**Post date:** [June 26, 2023, 10:43am UTC](https://discourse.julialang.org/t/color-cycling-in-glmakie-series/100834/8 "2023-06-26T10:43:10Z")

</div>

I think they just cycled through the colours associated with the figure but it’s a few years since I’ve used it.
