3

I have a problem with the plots I'm using for an article. After a lot of search on the web, I still haven't found a solution, so I'll try to describe my problem as clear as possible:

I'm plotting two parameters and have added their standard deviations with the fill-function. Because I don't want to use colors, I want to use different shadings for the space between the standard deviations. Until now the problem I have, is that I'm unable to specify, that the shading is consistent between the standard deviation of one parameter as you can see in the picture. I would like to have is one type of shading between the doted 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 darker shading is between the doted and the solid line, where it should be between the doted line!

I would be thankful for any thoughts on this!

Ratbert
  • 5,463
  • 2
  • 18
  • 37
Thomas Dupré
  • 33
  • 1
  • 4
  • possible duplicate of [MATLAB, Filling in the area between two sets of data, lines in one figure](http://stackoverflow.com/questions/6245626/matlab-filling-in-the-area-between-two-sets-of-data-lines-in-one-figure) – Bas Swinckels Jul 11 '15 at 17:26

2 Answers2

1

I assume that you used alpha to make all the lines of the plot visible. The problem is, that the two half-transparent fillings get added and therefore are darker where they overlap. So you cannot use alpha for what you want to achieve. But with the third argument of fill you can specify a solid color of the filling. To use different shades of grey, use the RGB-definition with a three-element-vector like [0.5 0.5 0.5].

Now you can generate the two fillings with different shades of grey without borders using 'LineStyle','none' or 'EdgeColor','none'. After just plot 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

Matt
  • 12,848
  • 2
  • 31
  • 53
0

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

For instance:

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

Note that I can't execute that code here since I don't have the data, this is a blind shot and it may contain small errors to correct.

Best,

Ratbert
  • 5,463
  • 2
  • 18
  • 37
  • Using this, I could only see one std, while the other one was hidden behind it. But that the use of transparent colors was the problem, was a good hint :) – Thomas Dupré Jul 12 '15 at 09:45