Change colors displayed on legend - Matlab - matlab

In order to fit with a global colororder scheme, I need to change the color of my surface plot
after I have created it. I have struggled to update the legend to the new color order.
I plot several surfaces and create a legend for them:
hSurf(i) = surf(hAx,...)
legend({'surface1','surface2','surface3'})
I modify the color of the surfaces successfully:
hSurf(i).CData = CDataNew;
How to update the legend to this new color order?
Legend does not automatically update when I change surface CData property.
Deleting current legend and creating a new one does not work either
Changing color order of axes (Ax.ColorOrder) also does not work, also not in any combination with the two items above.

Related

Why are the scatterplot colors in MATLAB R2021a different?

I have installed Matlab R2021a, and when I run the command scatterplot for a vector, I get a figure as below:
I mean black and yellow. However the default colors in older versions is as follows:
I mean the colors are white and blue.
My concern, I need my MATLAB shows the colors of the figure as shown in older version, I mean with white and blue colors.
The behavior indeed changed in R2021a as mentioned in the release notes:
Visual appearance updates to plots generated with eyediagram and scatterplot functions.
The eyediagram and scatterplot functions now provide black plot backgrounds by default.
You can change the colors as desired by you by modifying the properties of axis/figure as shown below:
%Taking the example from the documentation
d = (0:63)';
s = qammod(d,64);
scatterplot(s);
%Modifying the colors
h=gca; %Axis handle
h.Title.Color='k' %Color of title
h.Children.Color='b'; %Color of points
h.YColor='k'; %Y-axis color including ylabel
h.XColor='k'; %X-axis color including xlabel
h.Color ='w'; %inside-axis color
h.Parent.Color='w' %outside-axis color
Without modification, we get this:
After modification, as desired, we get this:

make different subplot have the same range of colors on matlab

I'm trying to plot several data on subplots, but each one have its own range of color (colorbar) and I want all to be the same. I can change the labels of the colorbar but if ranges are too different it would mostly show only one color. Is there a way to make matlab think that its all just one plot and then decide the colorbar scale accordingly?
To change colorbar label its quite easy:
allaxes = findall(f, 'type', 'axes');%f is the figure handle
for i=1:length(allaxes)
cc=get(allaxes(i),'Colorbar');
mm(i,:)=get(cc,'Limits');
end
limits=[min(min(mm)) max(max(mm))];
for i=1:length(allaxes)
cc=get(allaxes(i),'Colorbar');
set(cc,'Limits',limits);
end
Here there is an example (look for the one on the right):

Colorbar properties

I am trying to plot a contour with a colorbar that has a small values (10e-9). This value appears at top of the colorbar. How can I change the location of this value from top to bottom of the colorbar. I want to move this value beneath the colorbar because when I added label above the colorbar it overlapped with this value
I attached image for the figure.
You can accomplish what you want by first finding the handle to the color bar, then changing the yticklabel ticklabels property. This is a cell array of stings, one for each tick mark. You can fill in whatever you want to show there. The multiplier at the top will go away. With the text function you can add your own modifier anywhere you want. But I think it looks nicer within the axis label.
However, the simple solution is to change the units you plot. Multiply everything by 10e9 before plotting, then add a nano prefix to your units.

how to add additional label on x-axis on the rightmost in matlab figure?

I have the tick label set for the x-axis already and I also have the label set for the x-axis too. I am seeking a way to put an additional x label to the rightmost of the figure next to the x tick labels, is there any way to do so? Thanks
just like the following figure, the x ticks was added automatically and x label was added by the command xlabel. But I want to add one additional label "add'l" (red) in the figure. But I have many plots and/or subplots and the axes might be different, so I need to add that label with problem instead of manually.
I suggest using a uicontrol that will be carefully placed in the relevant area.
uicontrol('style','text',....);
If your UI is resizable, be sure to have the same units, i.e. if the text units are Normalized, then the axes units should be Normalized as well.
Check out this example on the MATPLOTLIB gallery page: http://matplotlib.org/examples/pylab_examples/alignment_test.html
It shows adding all kinds of different text to the axis.

matlab get color

I am using matlab for cluster visualization. I want to somehow get the color of my current cluster center fill in the plot and draw line of same color to cluster members. How can I get the color?
This is a generic answer to finding the color of any plot object in Matlab.
Select the object in the plot and use gco to get its color attribute.
c = get(gco,'Color');
Without any specific information about how and what you are plotting, it is not possible to give a more specific answer.