Matlab plots different shades between standard deviation lines

I have a problem with the sites I'm using for the article. After searching the internet a lot, I still haven't found a solution, so I'll try to describe my problem as much as possible:

I draw two parameters and add their standard deviations using the fill function. Since I don't want to use colors, I want to use different shades for the space between the standard deviations. So far, the problem I am having is that I cannot indicate that the shading is consistent between the standard deviation of one parameter, as you can see in the picture. I would like to have one type of shading between the dotted lines and another type of shading between the solid lines.

z = linspace(1,101,101)';

f=figure;
set(f,'Units', 'normalized', 'outerposition', [0 0 1 1]);

fill( [z' fliplr(z')],  [Parameter1_plus_std' fliplr(Parameter1_minus_std')], 'k');
alpha(0.4);
hold on
plot(normal,Parameter1_mean,'k','LineWidth',2);

fill( [z' fliplr(z')],  [Parameter2_plus_std' fliplr(Parameter2_minus_std')], 'k--');
alpha(0.2);
hold on
plot(Parameter2_mean,'k--','LineWidth',2);

      

enter image description here

In the picture, you can see that the dark shading is between the outlined and solid line, where it should be between the outlined line!

I would be grateful for any thoughts on this!

+3


source to share


2 answers


I assume you used alpha

to make all plot lines visible. The problem is that the two translucent fillings are added and therefore darker where they overlap. Therefore, you cannot use alpha

for what you want to achieve. But with the third argument, fill

you can specify a solid fill color. To use different shades of gray, use a 3-element vector RGB definition, for example [0.5 0.5 0.5]

.

Now you can generate two fills with different shades of gray without borders with 'LineStyle','none'

or 'EdgeColor','none'

. After just sketch all the lines on top.

Here is the code:



z = linspace(1,101,101)';

% generate some data to plot
normal = z;
Parameter1_mean = 9.225e-06.*z.^3-0.00159.*z.^2+0.07392.*z-0.4292;
Parameter1_plus_std = Parameter1_mean+0.08;
Parameter1_minus_std = Parameter1_mean-0.11;
Parameter2_mean = 9.225e-06.*z.^3-0.00156.*z.^2+0.07332.*z-0.4232;
Parameter2_plus_std = Parameter2_mean+0.11;
Parameter2_minus_std = Parameter2_mean-0.08;

% create figure
figure('Units', 'normalized', 'outerposition', [0 0 1 1]);
hold on

% plot the two solid fillings without border
fill([z',fliplr(z')], [Parameter1_plus_std',fliplr(Parameter1_minus_std')], 0.8*[1 1 1], 'EdgeColor','none');
fill([z',fliplr(z')], [Parameter2_plus_std',fliplr(Parameter2_minus_std')], 0.6*[1 1 1], 'EdgeColor','none');

% plot all the lines
plot(normal,Parameter1_mean,'k-','LineWidth',2);
plot(Parameter1_plus_std,'k-')
plot(Parameter1_minus_std,'k-')
plot(Parameter2_mean,'k--','LineWidth',2);
plot(Parameter2_plus_std,'k--')
plot(Parameter2_minus_std,'k--')

% some tweaking
xlim([min(z),max(z)])

      

This is the result:

result

+1


source


This is because you are using transparency. You can't achieve what you want with transparency, you have to use solid colors.

For example:

figure('Units', 'normalized', 'outerposition', [0 0 1 1]);
hold on

fill( [z' fliplr(z')],  [Parameter1_plus_std' fliplr(Parameter1_minus_std')], 0.4*[1 1 1], 'Linestyle', '-');
plot(normal,Parameter1_mean,'k-','LineWidth',2);

fill( [z' fliplr(z')],  [Parameter2_plus_std' fliplr(Parameter2_minus_std')], 0.2*[1 1 1], 'Linestyle', '--');
plot(Parameter2_mean,'k--','LineWidth',2);

      



Please note that I cannot execute this code here as I have no data, this is a blind shot and may contain small bugs to fix.

Best,

0


source







All Articles