Skip to content

Commit 4d702f8

Browse files
committed
Added all files for fill-between-area-curve
0 parents  commit 4d702f8

File tree

10 files changed

+737
-0
lines changed

10 files changed

+737
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*~
2+
*.asv

Example.mlx

62.8 KB
Binary file not shown.

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Fill Between Area Curve
2+
3+
[![View FillBetweenAreaCurve on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)]()
4+
5+
Version 1.0
6+
7+
<img src="examplePic.png">
8+
9+
## Description
10+
The Fill Between Area Curve creates a shaded area between two data series, effectively highlighting the region of overlap or difference.
11+
12+
## Dependencies
13+
For optimal performance and accurate graphs, please install the <b> Mapping Toolbox </b>.
14+
15+
## Syntax
16+
* `fillBetweenAreaCurve(x, y1, y2)` shades the area between 2 lines formed by y1 and y2
17+
* `fillBetweenAreaCurve(x, y1, y2, c)` shades the area between 2 lines formed by y1 and y2 with color c.
18+
* `fillBetweenAreaCurve(__, Name, Value)` specifies additional options for the FillBetweenAreaCurve using one or more name-value pair arguments. Specify the options after all other input arguments.
19+
20+
## Name-Value Pair Arguments/Properties
21+
22+
* `XData` Array containing values of x-coordinates for both plots y1 and y2. <b> Note: x-coordinates for both y1 and y2 should be common </b>
23+
* `Y1Data` y-coordinates of y1 plot
24+
* `Y2Data` y-coordinates of y2 plot
25+
* `Condition` The condition property selectively shades the area based on the condition provided by the user.
26+
* `ShadeInverse` Shades all the unshaded regions between 2 curves with a different color.
27+
* `OptimizePerformance` Calculate the vertices of triangles that compose the patch manually instead of asking patch to do it
28+
## Stylistic Name-Value Pair Arguments/Properties
29+
30+
* `FaceAlpha` Describes opacity of shaded area. If set to 1, the shaded area is completely opaque. If set to 0, the shaded area is completely transparent.
31+
* `FaceColor` Describes the color of shaded area specified by Condition
32+
* `InverseFaceColor` If ShadeInverse is set to true, we shade the unshaded region with InverseFaceColor
33+
* `Line1Color` Line color for plot describing y1 values
34+
* `Line2Color` Line color for plot describing y2 values
35+
* `XLabel` Label for x axis
36+
* `YLabel` Label for y axis
37+
* `Line1LineStyle` Line Spec for plot describing y1 values
38+
* `Line2LineStyle` Line Spec for plot describing y2 values
39+
* `Line1LineWidth` Line Width for plot describing y1 values
40+
* `Line2LineWidth` Line Width for plot describing y2 values
41+
* `Label1` Label for plot describing y1 values
42+
* `Label2` Label for plot describing y2 values
43+
* `Title` Title of the chart
44+
45+
46+
### How to use
47+
48+
```
49+
% Intialize some data
50+
x = linspace(0, 4 * pi, 20);
51+
y_sinx = sin(x);
52+
y_cosx = cos(x);
53+
54+
% Create a basic FillBetweenAreaCurve
55+
areaCurve = fillBetweenAreaCurve(x, y_sinx, y_cosx);
56+
57+
% Create a basic FillBetweenAreaCurve with magneta shading
58+
areaCurveMagneta = fillBetweenAreaCurve(x, y_sinx, y_cosx, 'm');
59+
60+
61+
% Create a FillBetweenAreaCurve with selective shading
62+
areaCurveSelectiveShading = fillBetweenAreaCurve(x, y_sinx, y_cosx, 'Condition', @(x, y1, y2) x > 2 & x < 4);
63+
areaCurveCondition2.ShadeInverse = false;
64+
65+
```

SECURITY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Reporting Security Vulnerabilities
2+
3+
If you believe you have discovered a security vulnerability, please report it to
4+
[security@mathworks.com](mailto:security@mathworks.com). Please see
5+
[MathWorks Vulnerability Disclosure Policy for Security Researchers](https://www.mathworks.com/company/aboutus/policies_statements/vulnerability-disclosure-policy.html)
6+
for additional information.

ValidationFunctions.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
classdef ValidationFunctions
2+
3+
methods
4+
function [x, y1, y2] = performAllValidations(obj, x, y1, y2)
5+
obj.validateDuplicateXValues(x);
6+
obj.validateInputs(x, y1, y2);
7+
[x, y1, y2] = obj.validateAndCleanMissingData(x, y1, y2);
8+
end
9+
10+
% Validate and Clean Missing Data in the inputs
11+
function [x, y1, y2] = validateAndCleanMissingData(obj, x, y1, y2)
12+
missing_x = find(isnan(x));
13+
missing_y = find(isnan(y1));
14+
missing_z = find(isnan(y2));
15+
missing_idx = union(union(missing_x, missing_y), missing_z);
16+
x(missing_idx) = [];
17+
y1(missing_idx) = [];
18+
y2(missing_idx) = [];
19+
end
20+
21+
function validateDuplicateXValues(obj, x)
22+
if numel(x) ~= numel(unique(x))
23+
error("X values cannot be duplicated. X array should entirely consist of unique x-values")
24+
end
25+
end
26+
27+
% Validate Inputs
28+
function validateInputs(obj, x, y1, y2)
29+
% If length of x is not equal to both y1 and y2, then we cannot create
30+
% the graph
31+
if numel(x) ~= numel(y1)
32+
error("invalid1:InputsAreInvalid", "Length of x is not equal to length of y1")
33+
end
34+
35+
if numel(x) ~= numel(y2)
36+
error("invalid2:InputsAreInvalid", "Length of x is not equal to length of y2")
37+
end
38+
end
39+
end
40+
41+
42+
end

examplePic.png

17.6 KB
Loading

0 commit comments

Comments
 (0)