changing background color for plot

28 次查看(过去 30 天)
TZ
TZ 2016-1-14
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.

回答(1 个)

Star Strider
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:

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by