changing background color for plot
조회 수: 28 (최근 30일)
이전 댓글 표시
hi, i am plotting a graph of machine parameters over time. the machine has 5 working modes and i want the background color to change according to a parameter i will define that will express the temporary machine state. for example for time vector from 1 to 100 white, then from 101 to 153 blue etc. is this possible on matlab? thanks.
댓글 수: 0
답변 (1개)
Star Strider
2016년 1월 14일
편집: Star Strider
2016년 1월 14일
The patch function will do what you want:
x = linspace(1, 300, 300); % Create Data
y = randi([20 80], 1, 300);
figure(1)
patch([1 100 100 1], [0 0 99 99], 'w')
hold on
p2 = patch([100 153 153 100], [0 0 99 99], 'b')
plot(x, y, '-k')
hold off
axis([1 300 0 99])
set(p2, 'FaceAlpha', 0.5) % Adjust Patch Transparency
The one caveat is to plot the patches first regardless of the transparency or other settings, and plot the data last. This plots the data on top of the patches:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Polygons에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!