File Exchange

image thumbnail

Filled area plot

version 1.0.1 (639 KB) by Javier Montalt Tordera
Linear plot, with extra functionality for area filling.

102 Downloads

Updated 21 Dec 2018

View Version History

View License

This contribution provides functionality to create filled area 2D linear plots, with full control over where and how areas are drawn.

The function 'shade' inherits its calling syntax from MATLAB's built-in 'plot' function, which hopefully should make its use intuitive. Some additional parameters, in the form of name-value pairs, allow controlling the filling behaviour. A live script is provided with multiple examples of usage.

Please do report any problems or suggestions and I will do my best to help.

Cite As

Javier Montalt Tordera (2020). Filled area plot (https://www.mathworks.com/matlabcentral/fileexchange/69652-filled-area-plot), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (20)

Serhii Tetora

Matthew Christie

Hi, apologies for the late replies. It looks like I stopped receiving notifications about this thread at some point. Although this may be too late, I will attempt to answer now for future reference.

@Charlotte Remy. For some complex vectorial figures MATLAB may choose to use an OpenGL renderer, which will embed a bitmap image in your figure. To make sure that you get a vectorial output, please use the Painters renderer instead.

print -depsc -painters filename.eps

See the docs for the print function for more information.

@Ajin Jiji Tom, I have not seen this issue. Would you be able to share some data?

@Aurea94. Curves do not need to meet any specific conditions that I’m aware of. For any two curves (x1, y1), (x2, y2), the following should fill the area between both.

shade(x1, y1, x2, y2, ‘FillType’, [1, 2; 2, 1]);

Use `help shade` or see the doc for more details. If this does not work for you, if you can share the curves I’ll be happy to take a look.

@Michael Souery. Sorry, linkdata is not currently supported. If you know how to support it please let me know!

@Martin Muehlegger. You can still use the option ‘Color’ to specify the color of the curves.

shade(x, y, ‘Color’, ‘red’); % red curves

Shadings themselves don’t have edges by default, but you can always add them manually.

```
h = shade(x, y); % h contains handlers to graphics objects
% for each graphics object
for i = 1:length(h)
% if the object is a patch (shadings are patches internally)
if isgraphics(h, ‘patch’)
h(i).LineStyle = ‘-’; % add an edge
h(i).EdgeColor = ‘red’; % set edge color
end
end
```

@Charlotte Remy. For some complex vectorial figures MATLAB may choose to use an OpenGL renderer, which will embed a bitmap image in your figure. To make sure that you get a vectorial output, please use the Painters renderer instead.

print -depsc -painters filename.eps

See the docs for the print function for more information.

Charlotte Remy

When using this function in a graph, the quality of my .eps file become very poor.

Antoine STUTZ

Ajin Jiji Tom

Hi, for some reason, when I reset axis to log scale, the shade disappears. Is there a way to fix that?

Axis=get(gcf,'CurrentAxes');set(Axis,'XScale','log');set(Axis,'XLim',[50 4000]);

Aurea94

Hello, do curves need to have any specific conditions? I have 2 curves which intersect each other multiple times and area between them is not filled.

Quark Q

Michael Souery

Is there a way for linkdata to work with the shade function? i.e. Automatically update the graph when variables are changing.

Martin Muehlegger

Is there an option to define edgecolor and linewdith just for shaded?

Russell Adams

Céline Heuzé

Jose Rego Terol

One of the most easy-to-use and pragmatic function ever.
Thank Javier!

Chrisso Anonymous

Josep Guasch

Hassan Arbabi

Joseph Mah

RHES

Allen

MATLAB Release Compatibility
Created with R2018b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!