Color the background based on value - matlab

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?

Related

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):

Drawing black areas in matlab contourf plot

I am generating a series of plots using matlab contourf. I need to do the following with the resulting figure. From this state:
Make this:
Important note: I know the coordinates of pixels which should be blackened.
The easiest way is possible to use ind2rgb, do the "blackening" manually, then use imagesc and deal with the axes propeerties. But using this I will lose the contourf graphics (e.g. the contour lines).
Any better ideas?
You can manipulate the figure colormap by adding black color to the one you use.
M=colormap;
M=[0,0,0 ; M];
colormap(M)
Now assign to the "should be black" pixels a value smaller than the minimum. This will map this value to the minimum color which is now black.
To assign the value efficiently use subs2ind

Overlapping graphs in matlab

I am drawing several graphs in the same plot in matlab by using the command, hold on.
My problem is that I am drawing points with big markersize on top of some of the graphs, and I would like theses points to have some specific color. Only what happens is that some of them will take some color and some others take another color, my guess is that the colors of my points get mixed with the colors of the graphs on top of which i put them. Is there a mean to ask matlap to overwrite whatever is under my points so that they get the color I assign to them?
Example:
x= 0:1:10;
plot(x,x,'r',x,-x,'b','linewidth',2)
hold on
plot(5,-5,'.',10,10,'.','MarkerColor',[0,0.5,0],'Markersize',24)
hold on
plot(5,5,'.',10,-10,'.','MarkerFaceColor',[0,0.75,0],'MarkerSize', 24)
Imagine that the curves are much more complicated than theses simple lines so no way to start having fun cutting them each time I want to represent a point...
Now my problem is that I would like that the points 5,-5 and 10,10 to have the same color. Namely 0 0.5 0 dark green. but their color get mixed depending on which line they lie.
If I specify their color as '.g' I don't get this problem, but the problem is that I got too many points to get covered by the few number of colors that are labeled by letters (eg 'r' 'b' 'k' etc..).
Thankfully
Note that 'MarkerColor' doesn't exist, so I suppose it's a type and you meant 'MarkerFaceColor', just like in the other plot.
Then, hold on once is enough, you don't need to repeat it every time you want overlap another plot.
Finally, I suggest you simply use 'Color' instead of MarkerFaceColor. This should display your dots with the wanted color.
x= 0:1:10;
plot(x,x,'r',x,-x,'b','linewidth',2)
hold on
plot(5,-5,'.',10,10,'.','Color',[0,0.5,0],'Markersize',24)
plot(5,5,'.',10,-10,'.','Color',[0,0.75,0],'MarkerSize', 24)

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(:))

Change color of line plotted with Tools>Basic fitting

I have several different data series that i would like to do a shape-preserving curve fit on.
I have the points plotted but when i go into Tools>Basic fitting>Shape-preserving interpolant the curve gets a random(?) colour and when i go to the next series the fit disapears.
How do make the fits stay for each data serie and how do change its colour afterwards using the toolbox in the plot window. If there is no easy solution is it possible with script, what to write?
This is what one data series looks like
%950
Wloss_950=950/(PWM1_1250CoreLoss+PWM4_1250CoreLoss)*(885.7312-632.7188)+632.7188;
Wloss_950=[Wloss_950;950/(PWM2_2000CoreLoss+PWM4_2000CoreLoss)*(405.8198-281.4403)+281.4403];
Wloss_950=[Wloss_950;950/(PWM3_2500CoreLoss+PWM5_2500CoreLoss)*(107-24.5466)+24.5466];
Wloss_950=[Wloss_950;950/(PWM3_4000CoreLoss)*24.5466];
Wloss_950=[Wloss_950;950/(PWM3_5000CoreLoss)*20.5796];
plot(speed, Wloss_950,'+','color', 'red')
In the figure window go to Tools -> Edit Plot then double tap on the line and editor window should open, in which you will be able to change colour, width, etc.