How to plot multiple vertical lines at specific points on x axis?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Heya :)
am 10 Mär. 2020
Kommentiert: Heya :)
am 11 Mär. 2020
I want to plot 0.8 at 0, 0.1 at 0.9 and 0.06 at -1.3. Here is what I am trying but I am onling getting a single line.
close all; clear all; clc;
x = -1.5:0.1:1.5;
y = zeros(1,31);
p1=plot([-1.3 1.3],[0 0.06]);
p2=plot([0.9 0.9],[0 0.1]);
p3=plot([0 0],[0 0.8]);
3 Kommentare
Ameer Hamza
am 10 Mär. 2020
See the updated answer. Refer to this link for more details about formatting the line: https://www.mathworks.com/help/matlab/ref/plot.html#btzitot-Color
Akzeptierte Antwort
Ameer Hamza
am 10 Mär. 2020
Bearbeitet: Ameer Hamza
am 10 Mär. 2020
You need to hold the axes to retain all plots
clc;
x = -1.5:0.1:1.5;
y = zeros(1,31);
ax = axes();
hold(ax);
p1=plot([-1.3 -1.3],[0 0.06],'r');
p2=plot([0.9 0.9],[0 0.1],'r');
p3=plot([0 0],[0 0.8],'r');
0 Kommentare
Weitere Antworten (1)
Jakob B. Nielsen
am 10 Mär. 2020
By default, matlab replaces plots on an axes instead of adding. However, if you set hold on, it will add instead of replacing, like so:
close all; clear all; clc;
x = -1.5:0.1:1.5;
y = zeros(1,31);
p1=plot([-1.3 1.3],[0 0.06]);
hold on %the key!
p2=plot([0.9 0.9],[0 0.1]);
p3=plot([0 0],[0 0.8]);
Siehe auch
Kategorien
Mehr zu Annotations 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!