Error trying to change colorbar color- data points dont reflect new color when colorbar changed
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am plotting data points with depth as y axis and latitude on the x axis. the color of the data should represent values based on variable, ttest22_table.deltaDIC, and change saturation based on the magnitude of this variable. the cmocean is the color range i am using.
Here is my code:
x = isfinite(ttest22_table.deltaDIC)
gscatter(ttest22_table.Lat(x), ttest22_table.ROVDepth(x), ttest22_table.deltaDIC(x), cmocean('-balance',32),"filled")
axis ij
set(gca,'Xdir','reverse')
ylim([0 1200])
hold on
plot(HI22.ASH.lat, HI22.ASH.dep, 'k--')
cb = colorbar();
ylabel(cb,'Difference DIC','FontSize',10,'Rotation',270)
caxis([min(ttest22_table.deltaDIC(x)) max(ttest22_table.deltaDIC(x))])
colormap(cmocean('-balance'))
When I go to "interactive colormap editor" to shift the colorbar so that white is at zero, it gives me this error and the data points do not change to reflect the new colorbar. I have tried to go inside the "colormap editor" and shift the colors that way, but the data points still do not update unless I save the shifted color bar to my workspace and then call that color bar specifically. When I do this, it saves the white color at the location that I put it, not at the value of zero. So in this case I cannot save the new colorbar range for all my data points and reuse it.
Warning: Error occurred while executing the listener callback for event MarkedDirty defined for class
matlab.graphics.axis.colorspace.MapColorSpace:
Error using matlab.graphics.illustration.ColorBar/MarkDirty
Attempt to modify the tree during an update traversal.
Error in matlab.graphics.illustration.ColorBar/attachAxesListeners
Error in matlab.graphics.illustration.ColorBar/attachAxesListeners>@(h,e)updateLimits(h,hObj)
0 comentarios
Respuestas (1)
Githin George
el 9 de Feb. de 2024
Hello Siobhan,
I have tried out the code you have provided with some dummy data and have made some observations out of it.
Firstly, the error message mentioned in the query seems to appear once in a while and does not seem to have any issues with respect to the functionality of colormaps in normal cases at my end.
Secondly, the “gscatter” plot return an array of “Line” objects which have colors assigned based on the arguments provided in the “gscatter” function call. In this case the list of colors provided as the argument is the nx3 matrix “cmocean(‘-balance’)”. But the “colormap” function will not affect the color of the “line” plots. Starting in MATLAB R2019b the “ColorOrder” property of the “axes” object defines the color of “line” objects.
It might be a difficult task to assign the color of the different “line” objects interactively, but you can extract the required color order that you would like and assign it during the “gscatter” function call.
For more information, please have a look at the documentation links for “gscatter” function and "colororder" function below.
On further inspection I have also noticed that setting the “ColorOrder” property on the “axes” object does not reset the color for the output handles of “gscatter” function. A workaround for this issue would be to plot each unique group one after other.
The following ML answers thread might prove useful to better understand usage of colormaps.
I hope this helps.
0 comentarios
Ver también
Categorías
Más información sobre Colormaps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!