JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.84k stars 355 forks source link

[BUG] More than three seriescolors break all further colors #4677

Open LRBaalmann opened 1 year ago

LRBaalmann commented 1 year ago

Details

When plotting lines with different choices of seriescolor, all colours after the third series are messed up. Weirdly, this affects not only the colours of further series but also, e.g., the colour of annotated text.

I've given a MWE below, which creates a simple colour gradient fading from a given colorant to not-quite-white, and then plots a number of lines changing along different gradients. This works fine for the first three lines, but all further gradients are messed up. It doesn't matter if the colour is given to the series by using line_z and seriescolor (c), or by directly creating an array of linecolor. It does not matter which gradients are used first: the first three always work as expected, and all latter ones are messed up.

What surprises me the most is that not only the series are affected but apparently the colours themselves: I've added a few text annotations in the bottom right corner of the plot, which work fine for the red and green text. The grey text, however, appears blue, just like the black colour gradient (bottom-most line) mostly consists of a blue gradient before abruptly changing to black.

Minimal Working Example

using Plots
using ColorSchemes

cgr(c) = cgrad(ColorScheme(range(range(parse(Colorant, c), parse(Colorant, :white), length=6)[5], parse(Colorant, c), 256)))
x = LinRange(0, 100, 10000)
y = LinRange(0, 10, 10000)
z = LinRange(1, 6, 10000)
p = plot(x, y, line_z=z, c=cgr(:blue), cb=:none, lw=10, label=":blue")
p = plot!(x, y .- 1, line_z=z, c=cgr(:red), cb=:none, lw=10, label=":red")
p = plot!(x, y .- 2, line_z=z, c=cgr(:green), cb=:none, lw=10, label=":green")
p = plot!(x, y .- 3, line_z=z, c=cgr(:purple), cb=:none, lw=10, label=":purple")
p = plot!(x, y .- 4, line_z=z, c=cgr(:darkorange2), cb=:none, lw=10, label=":darkorange2")
p = plot!(x, y .- 5, line_z=z, c=cgr(:gold2), cb=:none, lw=10, label=":gold2")
p = plot!(x, y .- 6, line_z=z, c=cgr(:black), cb=:none, lw=10, label=":black")
p = annotate!(75, -2, text("This text is :red", :red))
p = annotate!(75, -3.5, text("This text is :grey", :grey))
p = annotate!(75, -5, text("This text is :green", :green))
p=savefig("mwe.png")

Backends

I have only tested this behaviour on GR and PlotlyJS. For the latter, no lines are plotted at all, but the boxes in the legend and the text all have the correct colours.

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) x
pythonplot x
plotlyjs (x)
pgfplotsx x
unicodeplots x
inspectdr x
gaston x

Versions

Plots.jl version: [91a5bcdd] Plots v1.38.5 Backend version (]st -m <backend(s)>): [28b8d3ca] GR v0.71.7, [f0f68f2c] PlotlyJS v0.18.10 Output of versioninfo(): Julia Version 1.8.2 Commit 36034abf260 (2022-09-29 15:21 UTC) Platform Info: OS: Linux (x86_64-linux-gnu) CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-13.0.1 (ORCJIT, tigerlake) Threads: 8 on 8 virtual cores Environment: LD_LIBRARY_PATH = /home/lrb/intel/oneapi/mpi/2021.5.1//libfabric/lib:/home/lrb/intel/oneapi/mpi/2021.5.1//lib/release:/home/lrb/intel/oneapi/mpi/2021.5.1//lib:/home/lrb/intel/oneapi/debugger/2021.5.0/gdb/intel64/lib:/home/lrb/intel/oneapi/debugger/2021.5.0/libipt/intel64/lib:/home/lrb/intel/oneapi/debugger/2021.5.0/dep/lib:/home/lrb/intel/oneapi/compiler/2022.0.2/linux/lib:/home/lrb/intel/oneapi/compiler/2022.0.2/linux/lib/x64:/home/lrb/intel/oneapi/compiler/2022.0.2/linux/compiler/lib/intel64_lin::/home/lrb/Codes/cdf/cdfjava/lib:/home/lrb/Codes/cdf/lib JULIA_EDITOR = code JULIA_NUM_THREADS = 8 mwe

BeastyBlacksmith commented 1 year ago

Would be interesting to know if you can reproduce this in plain GR.

@jheinen what could cause this?

jheinen commented 1 year ago

Plots.jl probably uses indexed colors instead of direct colors in the gr backend?

In principle, it should work as in this example:

colormaps