Limit y-line in x-axis

171 views (last 30 days)
SuzieChan
SuzieChan on 13 Apr 2020
Edited: Adam Danz on 13 Apr 2020
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);

Accepted Answer

Ameer Hamza
Ameer Hamza on 13 Apr 2020
Edited: Ameer Hamza on 13 Apr 2020
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

More Answers (1)

Adam Danz
Adam Danz on 13 Apr 2020
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 Comments
Adam Danz
Adam Danz on 13 Apr 2020
Edited: Adam Danz on 13 Apr 2020
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 on 13 Apr 2020
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.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!