Color graph area in different shades
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
Adam Danz
2019년 3월 14일
편집: Adam Danz
2019년 3월 16일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!