Color graph area in different shades

2 Ansichten (letzte 30 Tage)
Maria445
Maria445 am 14 Mär. 2019
Bearbeitet: Adam Danz am 16 Mär. 2019
Hi everyone, I'd like to do something but don't know whether it's possible or not in Matlab:
I plotted GDP values over time in a 2d graph.
I colored the area below the curve, but I'd also like this colored area to have different shades: a stronger shade when GDP gets higher, and a pale one when GDP values are lower.
Is it possible to do it?

Akzeptierte Antwort

Adam Danz
Adam Danz am 14 Mär. 2019
Bearbeitet: Adam Danz am 16 Mär. 2019
Yep, it's possible.
Check out these examples using patch(). Your x and y values will be defined by the curve and the limits of your axes. The c value will be defined by GDP.
Demo
y = rand(1,100); % this would be GDP
x = linspace(1,200,100);
% x,y define the 'top' of the shape. Now we define and sides and bottom.
yy = [y, zeros(size(x))];
xx = [x, fliplr(x)];
figure()
patch(xx,yy, [y,zeros(size(y))])
colorbar
Note the redundancy between the y axis values and the colorbar values which indicate the same thing. The only added benefit is visual aesthetic.
  5 Kommentare
Adam Danz
Adam Danz am 15 Mär. 2019
Just saw your 2nd reply. Way to go!
Maria445
Maria445 am 15 Mär. 2019
Thank you so much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by