Connect points to the straight line
Ältere Kommentare anzeigen
Hi everybody,
How can I connect the points to the straight line in the figure ?
Thanks

2 Kommentare
David Hill
am 27 Aug. 2020
Are you talking about a stem() plot? Look at the stem() function.
Linda Scarzanella
am 27 Aug. 2020
Antworten (1)
Star Strider
am 27 Aug. 2020
Bearbeitet: Star Strider
am 27 Aug. 2020
Try this (with your own data):
x = 1:10; % Create Data
y = 2.5*rand(size(x)); % Create Data
stln = 0;
figure
plot(x, stln+zeros(size(x)), '-r') % Straight Line
hold on
plot(x, y, 'xk') % Points
plot([x; x], [zeros(size(y))+stln; y], '-g') % Connecting Lines
hold off
ptlbls = compose(' %2.1f', y);
text(x, y, ptlbls, 'HorizontalAlignment','left', 'VerticalAlignment','middle')
axis([0 11 -0.1 2.5])
Make appropriate changes to use it with your data.
4 Kommentare
Linda Scarzanella
am 27 Aug. 2020
Bearbeitet: Linda Scarzanella
am 27 Aug. 2020
Star Strider
am 27 Aug. 2020
It works with my test data, or I would not have posted it. I would have to see your code and data to determine what the problem is.
figure
stem(x, y)
ptlbls = compose(' %2.1f', y);
text(x, y, ptlbls, 'HorizontalAlignment','left', 'VerticalAlignment','middle')
If the horizontal line is something other than at 0, use the BaseValue name value pair to specify it, and use ShowBaseLine. to turn it 'on' or 'off'.
Linda Scarzanella
am 28 Aug. 2020
Star Strider
am 28 Aug. 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Kategorien
Mehr zu Graphics Performance finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!