How to fill the stair plots with some color.
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
shane watson
am 26 Sep. 2019
Kommentiert: shane watson
am 5 Dez. 2019
Hello,
Below are plots (subplot) and having Figure 1 I wanted to fill these stairs (inside) same as figure 2 . I really appreciate your help in this regard.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/239882/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/239882/image.png)
Figure: 1
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/239883/image.png)
Figure 2
2 Kommentare
Akzeptierte Antwort
Adam Danz
am 26 Sep. 2019
Bearbeitet: Adam Danz
am 26 Sep. 2019
This solution reproduces the (x,y) coordinates for the staircase and then uses fill() to fill in the area under the stairs.
% Create demo plot
X = linspace(0,4*pi,40);
Y = sin(X);
figure
sh = stairs(Y);
hold on
% Get the (y,x) coordinates from the original inputs or from
% the xdata and ydata properties of the stair object which will
% always be row vectors.
bottom = -1.5; %identify bottom; or use min(sh.YData)
x = [sh.XData(1),repelem(sh.XData(2:end),2)];
y = [repelem(sh.YData(1:end-1),2),sh.YData(end)];
% plot(x,y,'y:') %should match stair plot
% Fill area
fill([x,fliplr(x)],[y,bottom*ones(size(y))], 'g')
![190926 064128-Figure 1.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/239893/190926%20064128-Figure%201.png)
9 Kommentare
Adam Danz
am 5 Dez. 2019
Bearbeitet: Adam Danz
am 5 Dez. 2019
I just tested my suggestion with your code and it works perfectly.
x = time
y = EP
% See rest of my suggestion
If it still doesn't work you'll need to explain what's not working and I suggest doing that in a new question rather than extending this thread since the topic slightly differs (you could provide the link to the new question here).
![191205 001733-MATLAB Online R2019b.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/252972/191205%20001733-MATLAB%20Online%20R2019b.png)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!