How to show two axis on a plot only where i want them
조회 수: 16 (최근 30일)
이전 댓글 표시
Hi Matlab Gurus,
I have the plot below, and i have two y axis, one on the left and one on the right, which are different to each other.
What i would like to do is only show the numbers on the y-axis (left and right), where the horizontal lines are
So i can draw a horizontal line using the left axix, and i can draw another horizonal line using the right axis.
then i want the axis to only show exactly where those lines are, not evenly spread based on itself, but only where the lines are, so that i know the exact value of the lines at both the left and right axis.
Any help would be highly appreciated.
댓글 수: 0
채택된 답변
Joel Lynch
2021년 6월 9일
yyaxis left; % Sets the current y-axis left
left_ax = gca; % Creates "left_ax" variable which stores the current (left) y-axis
yyaxis right; % Sets the current y-axis right
right_ax = gca; % Creates "right_ax" variable which stores the current (right) y-axis
With these handles, you can find and edit pretty much any feature of the axis. For Tick Labels
left_ax.YTick = linspace(0,1,5); % Create 5 equally spaced ticks, for example
If your horizontal lines are meant to be grid lines, you can simple add them with
grid on
and they should conform to the tick labels on the active axis.
댓글 수: 5
Joel Lynch
2021년 6월 10일
right_ax.ylim = [min(right_ax.YTick), max(right_ax.YTick)];
should work, after YTick has been set.
추가 답변 (1개)
darova
2021년 6월 9일
try this yticks
h = plot(0:10,sin(0:10));
yy = 0:0.2:1;
[x,y] = ndgrid([0 10],yy);
line(x,y)
yticks(yy)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!