Limit y-line in x-axis

65 ビュー (過去 30 日間)
SuzieChan
SuzieChan 2020 年 4 月 13 日
編集済み: Adam Danz 2020 年 4 月 13 日
Hi!
I want to:
  • limit the first y-line on my graph to end at the divide at x = 10200.
  • to make the 2nd y-line start from x=10200 to the end of the graph.
(It seems to not to be a property of the y-line function already).
What code can do this?
figure('units','normalized','outerposition',[0 0 1 1]);
hold on
set(gcf,'color','w');
set(gca,'linewidth',4, 'fontname','times')
h1 = scatter(A{:,1}, A{:,2}, 'x', 'k', 'LineWidth',1);
h2 = scatter(B{:,1}, flipud(B{:,2}), 'k', 'LineWidth',1);
xline(10200,'k','LineWidth',5, 'FontSize',12);
yline(360,'-.k','Max. Channel Elevation', 'LineWidth',2, 'FontSize',20, 'fontname','times');
yline(461,'-.k','Max. Channel Elevation', 'LineWidth',2, 'FontSize',20, 'fontname','times');
title('Drainage Basin Reorganisation');
xlabel('Distance From Base Level (m)');
xtickangle(45);
ylabel('Elevation (m)');
box on
lg = legend([h1, h2],'Sheer Water Channels','Brent Channels', 'Location','southWest');
set(lg, 'Location', 'northwest', 'FontSize', 28);

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 13 日
編集済み: Ameer Hamza 2020 年 4 月 13 日
yline() does not have any options for limiting its x-range. You need to use line
line([0 10200], [360 360], '-.k', 'LineWidth',2);
line([10200 18000], [461 461], '-.k', 'LineWidth',2);
For adding text, you will need to use text() function: https://www.mathworks.com/help/releases/R2020a/matlab/ref/text.html

その他の回答 (1 件)

Adam Danz
Adam Danz 2020 年 4 月 13 日
To shift data to the right, you just need to add a constant value to all x-coordinates.
To shift data to the left, you just need to subtract a constant value from all x-coordinates.
Find the max x-value from the data on the left of x=10200 and compute the difference between that max value and 10200. That tells you how much to add.
Find the min x-value from the data on right of x=10200 and compute the diffeerence between that min value and 10200. That tells you how much to subtract.
  3 件のコメント
Adam Danz
Adam Danz 2020 年 4 月 13 日
編集済み: Adam Danz 2020 年 4 月 13 日
I interpretted your question differently. My interpretation was that you needed to shift your data toward 10200. Looks like Ameer set you straight.
Ameer Hamza
Ameer Hamza 2020 年 4 月 13 日
I think this issue was apparent from the question statement, and I answered to that actually. Maybe the OP edited the question statement between the time you responded and the time I saw it. Or maybe the confusion was caused by OP using y-line instead of yline, which can be mistaken for a line parallel to y-axis.

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

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by