问题
I am trying to write a script for this colorbar:
Where could I find such a script?
回答1:
Colorbars exist in Matlab (in fact, the command is colorbar). You can even change the color setting, e.g. by colormap winter
(which will change both, the figure itself and the corresponding bar as its ledgend). You can also set the tick labels: colorbar('TickLabels',{'Extreme','Severe','Strong'})
, but what you won't have are those crisp boundaries.
I feel that you are not looking for a true colorbar but rather a way to mimic a color bar to a plot, which is not suited for a Matlab-native colorbar (that are plots with a continously chaning color map/gradient). So what you are looking for is the function rectange
to build your own colorbar
EDITED:
As @LuisMendo noted, you can set your own colormap by specifying a ?x3
matrix with RGB values (which are in matlab in the range of [0,1]
, so you have to divide the "normal" values by 256). If you then place the ticks in the center of those values, you have everthiny you want + you can even name the colors as you like by setting the tick-labels
colormap([1 1 0; 0 1 1; 1 0 1])
colorbar('Ticks', [1/6 3/6 5/6], 'TickLabels',{'Extreme','Strong','None'})
来源:https://stackoverflow.com/questions/59761885/commands-for-a-specific-colorbar