Open cmichelenstrofer opened 3 years ago
After several hours was able to figure it out. This should not be this difficult. Is there a better way or can you implement one? At the very least document this.
using PlotUtils: palette
using GLMakie
colors = palette(:tab10)
x = 1:5
y = rand(5)
lines(x, y, color=colors[1]);
scatter!(x, y, color=colors[2])
current_figure()
I recently faced this difficulty. Makie cycles colors only within the same plot object type. Perhaps useful in very complex graphics, this can be cumbersome in simple cases, as you exemplified. What I would like to have is some option to step cycle within the same plot object type, or to set color from the default color map using integers. Adjusting your example, it would look like the following.
using GLMakie
x = 1:5
y = rand(5)
lines(x, y)
scatter!(x, y, color=2)
current_figure()
But you can achieve your goal as follows.
using GLMakie
x = 1:5
y = rand(5)
lines(x, y, color=1, colormap=:tab10, colorrange=1:10)
scatter!(x, y, color=2, colormap=:tab10, colorrange=1:10)
current_figure()
As mentioned in the documentation. But in my opinion, there shouldn't be the need to specify colormap
and colorrange
. If you don't, you get ERROR: UndefVarError: `intens` not defined
, whatever that means.
As you already know how to select a specific color from a palette, would you consider renaming the issue to something like “Make selecting color from a color map easier” or “Allow indexing colors from the default color map”?
But you can achieve your goal as follows.
using GLMakie x = 1:5 y = rand(5) lines(x, y, color=1, colormap=:tab10, colorrange=1:10) scatter!(x, y, color=2, colormap=:tab10, colorrange=1:10) current_figure()
You need to pass colorrange
a tuple rather than a range e.g. (1,10)
not 1:10
otherwise it errors
You need to pass
colorrange
a tuple rather than a range e.g.(1,10)
not1:10
otherwise it errors
That's weird. In my experience, it doesn't raise errors, but I can see that in the documentation tuples are used for a colorrange
value. I must have used a range, because the name was colorrange. It appears to be undefined behavior, but it would be nice, and, in my opinion, more intuitive, to officially accept it.
There is also Makie.interpolated_getindex(colormap, i01)
, Makie.to_colormap()
, Makie.resample_cmap()
I guess the goal for this would be to make some more convenient function and document it?
I think the documentation is key here, a user recently mentioned that figuring out how to sample from a colormap was pretty hard for them.
I would like to select a specific color from a palette(e.g.
:tab10
) for my line or scatter plots. This should be pretty simple but I cannot find a single answer online