changing background color for plot
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Star Strider
el 14 de En. de 2016
Editada: Star Strider
el 14 de En. de 2016
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 comentarios
Ver también
Categorías
Más información sobre Polygons en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!