plotting a horizontal line at each data point

3 ビュー (過去 30 日間)
P Rakesh Kumar Dora
P Rakesh Kumar Dora 2020 年 4 月 20 日
コメント済み: Star Strider 2020 年 4 月 21 日
How to plot a horizontal line at each co-ordinate.Here consider 1a,1b, 1c etc as horizontal points, energy values as vertical points.Also how to indicate which color is used for which.pls help.
  1 件のコメント
Ilian
Ilian 2020 年 4 月 20 日
This is not an elegant solution but you can probably solve this with a loop and line()

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2020 年 4 月 20 日
Try this:
x = 1:10; % Create Data
yh = rand(size(x))-2; % Create Data
yl = rand(size(x))-4; % Create Data
hl = @(x,y,l,c) plot(x+[-l l], y*[1 1],c); % Anonymous Function To Draw Horizontal Lines
figure
hold on
for k = 1:numel(x)
hl(x(k),yh(k),0.5,'b')
hl(x(k),yl(k),0.5,'r')
text(x(k),yh(k), sprintf('%5.2f',yh(k)), 'VerticalAlignment','bottom', 'HorizontalAlignment','center')
text(x(k),yl(k), sprintf('%5.2f',yl(k)), 'VerticalAlignment','top', 'HorizontalAlignment','center')
text(x(k),yh(k),'\uparrow', 'VerticalAlignment','top', 'HorizontalAlignment','center')
text(x(k),yl(k),'\downarrow', 'VerticalAlignment','bottom', 'HorizontalAlignment','center')
text(x(k), mean([yh(k) yl(k)]), sprintf('%5.2f',(yh(k)-yl(k))), 'VerticalAlignment','middle', 'HorizontalAlignment','center')
plot([1 1]*x(k),[yl(k) yh(k)+sign(yh(k))*0.1], '-k', 'LineWidth',0.5)
end
yl = ylim;
ylim(yl+[-1 1]*0.2)
.
  10 件のコメント
P Rakesh Kumar Dora
P Rakesh Kumar Dora 2020 年 4 月 21 日
Thanks.
Star Strider
Star Strider 2020 年 4 月 21 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2020 年 4 月 20 日
My first thought when I saw your picture was errorbar.

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by