matlab get color - matlab

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.

Related

Change colors displayed on legend - 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.

MATLAB - Filling a map with a gradient of two colors based on city colors

I have a map where each city is classified somewhere between r=0 and r=1, which I have plotted in the following image using the color [r 0 1-r], which gives me a color between red and blue for each city. In this case, the circles are just for testing, and should not be visible in the final image. Currently the circle radius represents the amount of data available for each city. The country outline uses the borders data. Here's the result so far:
My goal is to fill the map with a non-linear gradient of red/blue, taking into account this data and extrapolating it.
(In this example the border seems pretty linear, but that's not always the case, hence the need for a non-linear gradient)
Can anyone point me in the right direction? Thank you!
What you're probably looking for is griddata, which lets you interpolate (unevenly) scattered data points using various interpolation methods. So you could evaluate the interpolation on a grid (which can be created using meshgrid or ndgrid) and then e.g. use surf to plot the interpolated function.

Color the background based on value

I have collected multiple time series for evaluation and further use in MATLAB.
I am aware there are ways to change the color of a plot based on its value.
But in my case I would like to change the background color of a plot based on one data series and have other plots in front.
Maybe the words don't explain it too well, so I tried to make a clear example:
In this plot, the background was colored according to data series 1, in the foreground data series 2 is plotted as a line plot in blue.
Is there a way to achieve this using MATLAB?

I have a 2D plot in Matlab where I want to specify the RGB value for each point to vary to color

I am trying to plot a 2D line in Matlab with a color that varies based on an RGB code that I assign to each point. The code below works well for a given colormap ('col' values defining the color), but I am trying to keep tighter control over the color assignment, so that values always render the same color across multiple charts.
surface([x;x],[y;y],[z;z],[col;col],...
'facecol','no',...
'edgecol','interp',...
'linew',2);
The question is how do you decide which colour does each point have? defining the colormap is easy (shown below).
col=colormap(hot(128)) %% or other colour style like hsv or jet
if you have a variable (lets called it V) that for each point has a certain value and you want the colours to change based on that:
first define the values for the extremes in the colormap:
min_col=0; %%%can be the minimum of V
max_col=1; %%%can be the maximum of V
Then interpolate to your data
new_col=interp1(linspace(min_col,max_col,length(col)),col, V(:))

Colorfill the boxes in a boxplot in Matlab

Is there a way to fill the boxes in a boxplot in Matlab?
I was able to change the color of the boundaries of the boxes using the colorgroup option of the boxplot function (http://www.mathworks.com/help/stats/boxplot.html), but could not find any option to change the or fill the color of the space inside box itself.
Edit:
So, I went through the code at the link (http://www.mathworks.com/matlabcentral/newsreader/view_thread/300245) pointed out user1929959 in the comments. However, i am new to Matlab and I would really appreciate a brief explanation of what the code does. Here is the code from that link:
load carsmall
boxplot(MPG,Origin)
h = findobj(gca,'Tag','Box');
for j=1:length(h)
patch(get(h(j),'XData'),get(h(j),'YData'),'y','FaceAlpha',.5);
end
I am also open to other solutions. Thanks.
With FINDOBJ function you search for graphic objects with tag equals to 'Box' in the current axes (gca = get current axis handle).
Tags for all objects in boxplot you can find in the official MW documentation (just before examples):
http://www.mathworks.com/help/stats/boxplot.html
FINDOBJ returns handles to all objects it found into variable h, which is double array. You use the handle to modify the object properties. You can see all properties for a given handle with get(h(1)) or inspect(h(1)).
For example you can set line width:
set(h,'LineWidth',3)
Since box is a line object it doesn't have FaceColor or FaceAlpha (transparancy) properties as for patch, so you cannot color it directly. You have to draw patches over it with yellow color (set by 'y' parameter) and 0.5 transparancy. You get XData and YData properties to get the patch coordinates. See here for all patch properties.
Again if you don't know what some function does, always check matlab documentation with help function_name or doc function_name.