Limit y-line in x-axis
61 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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);
0 commentaires
Réponse acceptée
Ameer Hamza
le 13 Avr 2020
Modifié(e) : Ameer Hamza
le 13 Avr 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
0 commentaires
Plus de réponses (1)
Adam Danz
le 13 Avr 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 commentaires
Ameer Hamza
le 13 Avr 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.
Voir également
Catégories
En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!