Draw vertical lines on a plot
3 ビュー (過去 30 日間)
表示 古いコメント
Hi,
I have a plot and I want to draw several vertical lines (about 40 of them) at specific locations on the plot. How do I go about it? Any code that I can put all those locations in and automatically mark those regions of the plot with vertical lines for me? Thanks!
0 件のコメント
採用された回答
Luna
2019 年 12 月 3 日
編集済み: Luna
2019 年 12 月 3 日
There is a built-in function for that.
Here is sample code:
regions_to_be_marked = randn(40,1); % array of the points you want to plot vertical line (x axis values)
x_data = randn(100,1); % x data to plot
y_data = randn(100,1); % y data to plot
hFig = figure; % figure handle
hAxes = axes(hFig); % axis handle
hPlot = plot(hAxes,x_data,y_data,'LineStyle','none','Marker','*'); % your actual plot
hold on; % holds current plot
% plot each region in for loop
for i = 1:numel(regions_to_be_marked)
xline(hAxes, regions_to_be_marked(i),'LineWidth',2,'Color','red');
end
その他の回答 (1 件)
参考
カテゴリ
Find more on Annotations in Help Center and File Exchange
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!