I have a figure where I am plotting a line and want that line to be colored according to some other array. How do I use only part of a colormap? Or even reverse a sub-section of a colormap?
I don’t have a MWE, but the relevant parts of my code are below:
nodalplot = nothing
for coordsi in coords_list
global nodalplot
nodalplot = lines!(ax, coordsi[:, 1], coordsi[:, 2], coordsi[:, 3]; color=freqnodal, linewidth=10, colormap=:brg)
end
Colorbar(fig[1, 2], nodalplot)
So for example, I only want to use the blue → red section of the brg
colormap. I can set the colorrange
while plotting the lines, but it doesn’t allow me to change the limits of the Colorbar.
nodalplot = lines!(ax, coordsi[:, 1], coordsi[:, 2], coordsi[:, 3]; color=freqnodal, linewidth=10, colormap=:brg, colorrange=(0.315, 0.35))
Colorbar(fig[1, 2], nodalplot)
Trying to pass a colorrange
arugment into Colorbar
gives the error:
ERROR: Both colorrange + limits are set, please only set one, they're aliases. colorrange: (0.315, 0.35), limits: (0.315, 0.35)
whereas passing a limits
argument gives the error:
ERROR: You should not pass the `limits` attribute to the colorbar when constructing it using an existing plot object. This attribute is copied from the plot object, and setting it from the colorbar will make the plot object and the colorbar go out of sync.