# Logarithmic colorbar for multiple colored plots

**URL:** https://discourse.julialang.org/t/logarithmic-colorbar-for-multiple-colored-plots/107205
**Category:** Visualization
**Tags:** plots, gr
**Created:** [December 6, 2023, 9:25am UTC](https://discourse.julialang.org/t/logarithmic-colorbar-for-multiple-colored-plots/107205 "2023-12-06T09:25:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![maltee1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maltee1/32/204977_2.png) [@maltee1](https://discourse.julialang.org/u/maltee1)
#### Post date: [December 6, 2023, 9:25am UTC](https://discourse.julialang.org/t/logarithmic-colorbar-for-multiple-colored-plots/107205/1 "2023-12-06T09:25:47Z")

</div>

Hi,

I have a series of plots, each associated with a different value of a parameter called `k`. The idea was to plot each line with a different color from a colormap and have the colorbar indicate which value of `k` each plot is associated with, rather than using a legend. The plots are created by a loop, creating one plot per iteration.

I’m quite happy I found the parameter line\_z, which automatically creates a colorbar and assigns the right color to the plot, rather than having to create both of them seperately, as suggested in some places on the internet.

However, the parameter `k` is exponentially spaced (from 5 to 500, so 50 is the midpoint) so I need logarithmic scaling.

`colorbar_scale=:log10` seems to do that for the colorbar just fine, but the plots don’t follow, so the colors don’t match. I suppose one option would be to take the log of `k` instead and change the tick labels, but I haven’t figured out how to change tick labels and that also seems like an ugly workaround for something that should work out of the box. Setting `zscale=:log10` just prints a warning `No strict ticks found`.

I’m using this before the loop:

```julia
using Plots
plot(xlabel="\$L_v\$ (pu)", ylabel="frequency (Hz)", colorbar_title="k")

```

This at the end of the loop

```julia
plot!(x, y, seriescolor=:roma, line_z = k, label="", colorbar_scale=:log10)

```

and somehow I still need to run `plot!()` after the loop for the plot to actually show up, I’m not quite sure why.  
This is without the parameter `colorbar_scale`, plot colors and colorbar locations match, but you can’t tell the first 2 plots apart, because they have almost the same color:  
 ![plot_23](https://global.discourse-cdn.com/julialang/original/3X/b/8/b8e11e8921c9fbcaf42213a29374929b4dc5974b.png)

This is with the parameter `colorbar_scale`, the colorbar looks fine, but the plots don’t look any different and thus no longer match the values indicated by the colorbar  
 ![plot_22](https://global.discourse-cdn.com/julialang/original/3X/9/9/99ce5c5baa6d601b9bd80e3a99ee9cb9048f3347.png)

Taking the log10 of `k` gives me correct plot colors, but the colorbar scale if obviously wrong:  
 ![plot_24](https://global.discourse-cdn.com/julialang/original/3X/6/f/6f4161fbde10cbe73a663104f8d1e748cc1979ee.png)

I was thinking I could use the latter and modify the tick labels, but I haven’t figured out how to do that and I also think that I should not need to do this - the correct color scaling should work out of the box.

My problem seems very similar to what is discussed in [this issue](https://github.com/MakieOrg/Makie.jl/issues/1405), but it says the issue is solved and I don’t really know how to transfer the workarounds to my problem without major changes to the plotting code.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [December 6, 2023, 9:59am UTC](https://discourse.julialang.org/t/logarithmic-colorbar-for-multiple-colored-plots/107205/2 "2023-12-06T09:59:40Z")

</div>

> [@maltee1](#):
>
> My problem seems very similar to what is discussed in [this issue](https://github.com/MakieOrg/Makie.jl/issues/1405), but it says the issue is solved

The link provided suggests the issue is solved in `CairoMakie` and `PythonPlot`, but not in `Plots`?

---

<div class="post-metadata">

### Author: ![maltee1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maltee1/32/204977_2.png) [@maltee1](https://discourse.julialang.org/u/maltee1)
#### Post date: [December 6, 2023, 10:27am UTC](https://discourse.julialang.org/t/logarithmic-colorbar-for-multiple-colored-plots/107205/3 "2023-12-06T10:27:41Z")

</div>

Yeah, that seems to be the case, also the issue is filed with Makie. I’m still a bit confused about the different Plotting options in Julia. Should I file an issue with Plots?

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [December 6, 2023, 10:53am UTC](https://discourse.julialang.org/t/logarithmic-colorbar-for-multiple-colored-plots/107205/4 "2023-12-06T10:53:52Z")

</div>

There is probably already an issue about this in Plots.jl, but please do some searching before opening a new one.

It affects the `gr()` backend, but not e.g. `pythonplot()`.

Simple test code:

```julia
using Plots; pythonplot(dpi=100)

x = [0, 1]
y = [i*x for i in 1:5]
z = [10^i for i in 1:5]

p = plot()
foreach(i->plot!(x, y[i], c=:jet, line_z=z[i], label="", colorbar_scale=:log10), 1:5)
p

```

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [December 6, 2023, 7:47pm UTC](https://discourse.julialang.org/t/logarithmic-colorbar-for-multiple-colored-plots/107205/5 "2023-12-06T19:47:55Z")

</div>

> [@maltee1](#):
>
> Taking the log10 of `k` gives me correct plot colors, but the colorbar scale is obviously wrong:

Not if we define the plot keyword argument `colorbar_title` as: `colorbar_title="log10(k)`"
