Make a plot with gradient shaded confidence intervals
Mostra commenti meno recenti
Dear all,
I would like to fill the red shaded area in the plot below using a gradient fill (ideally with a jet colormap), so that the area between the blue line and the upper red dashed line goes from red to blue and the area between the blue line and the lower red dashed line goes from red to blue.
x = Data(:,1);
y = Data(:,2);
y10 = Data(:,3);
y90 = Data(:,4);
figure
plot(x, y, 'b', 'LineWidth', 2);
hold on;
plot(x, y10, '--r');
plot(x, y90, '--r');
fill([x; flipud(x)], [y10; flipud(y90)], 'r',...
'FaceAlpha', 0.1, 'EdgeColor', 'none');
hold off;
legend('Median', '10th-90th Percentiles', 'Location', 'best');
grid on;

Just to give an idea, something like this (without color steps but with a gradient fill):

I have tried myself, but I can't really find a nice (and fast) solution.
I have attched the Data file.
Any help would be grately appreciated!
1 Commento
Umar
il 7 Lug 2024
Hi Simone,
To achieve a gradient fill effect in the specified red shaded area of the plot, we can use a combination of surf and colormap functions in Matlab. Here's a step-by-step guide to implement this:
Create a Meshgrid: Generate a meshgrid that covers the area to be filled with a gradient. This meshgrid will define the coordinates for the gradient fill.
[X, Y] = meshgrid(x, linspace(min(y10), max(y90), 100));
Calculate Colors: Determine the colors for the gradient fill based on the jet colormap. You can adjust the colormap to suit your preferences.
colors = jet(100); % Use jet colormap with 100 colors
Plot the Gradient Fill: Use the surf function to plot the gradient fill on the meshgrid.
figure; surf(X, Y, zeros(size(X)), 'CData', colors, 'FaceColor', 'interp', 'EdgeColor', 'none'); view(2); % 2D view for a flat gradient fill
Adjust Plot Settings: Customize the plot appearance to match the original plot.
hold on; plot(x, y, 'b', 'LineWidth', 2); plot(x, y10, '--r'); plot(x, y90, '--r'); hold off; legend('Median', '10th-90th Percentiles', 'Location', 'best'); grid on;
By following these steps, you can create a gradient fill effect in the specified red shaded area of the plot, transitioning smoothly from red to blue based on the jet colormap. Feel free to adjust the colormap, shading, or other parameters to achieve the desired visual effect.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su DALSA Sapera Hardware in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







