필터 지우기
필터 지우기

yyaxis 'right' - can I have tick marks on both sides?

조회 수: 29 (최근 30일)
dormant
dormant 2022년 8월 17일
댓글: Adam Danz 2022년 10월 6일
I'm creating a figure to illustrate data availability/quality. It's one plot with no subplots. See attached.
I add a small plot at the bottom of the main plot using yyaxis 'right' and fiddling with the y limits. I can't work out how to put the tick marks and labels on both sides for just this bottom plot.
Can this be done?
Here is the relevant part of my script - it is not possible to share the whole script and the data here.
figure;
plot( XP1, YP1, 'b|', 'MarkerSize', 10 );
plot( XP2, YP2, 'r|', 'MarkerSize', 10 );
stations = [ "MSCP (0.7km)"; "MSUH (1.0km)"; "MSS1 (1.3km)"; "MBFR (2.0km)"; "MBLG (2.1km)"; "MBLY (2.1km)"; "MBRY (2.4km)"; ...
"MBBY (3.3km)"; "MBHA (3.5km)"; "MSMX (3.7km)"; "MBGH (3.8km)"; "MBWH (3.9km)"; "MBWW (5.0km)" ];
nsta = length( stations );
ylim( [0 nsta+2] );
yticks( 1:nsta );
yticklabels( stations );
h=gca;
h.YAxis.TickLength = [0 0];
h.XAxis.TickLength = [0 0];
set(h, 'Ydir', 'reverse');
box on;
yyaxis right;
bar( ngoodSta, 1.0, 'k' );
ylim( [0 60] );
yticks( [0 2 4] );
ax = gca;
ax.YAxis(2).Color = 'k';
  댓글 수: 2
Rohit
Rohit 2022년 10월 6일
Hi,
My initial investigation shows that it is not currently possible to add another data scale on the left y-axis since it is already being used for plotting “YP1”, “YP2” data. Furthermore, it will be misleading since the resulting left y-axis will be representing categorical as well as numerical data. Instead, it is recommended to use the “subplot” function.
Consider the sample example below:
hfig=figure;
x1=[1,2,3,4];
y1=[1,2,2,1];
x2=[2,4,6,8];
y2=[2,3,1,1];
vals=[0,2,4];
subplot(4,1,1:3);
plot( x1, y1, 'b|', 'MarkerSize', 10 );
hold on;
plot( x2, y2, 'r|', 'MarkerSize', 10 );
stations = ["stat1", "stat2","stat3"];
nsta = length( stations );
ylim( [0 nsta+2] );
yticks(1:nsta );
yticklabels( stations );
h=gca;
h.YAxis.TickLength = [0 0];
h.XAxis.TickLength = [0 0];
set(h, 'Ydir', 'reverse');
box on;
subplot(4,1,4);
yyaxis right;
bar( [1,1,2,3,4,2], 1.0, 'k' );
ylim([0,6])
yticks( vals );
ax = gca;
ax.YAxis(2).Color = 'k';
yyaxis left;
ylim([0,6])
yticks( vals );
ax = gca;
ax.YAxis(2).Color = 'k';
Here, dummy data(“x1”,”x2”,”y1”,”y2”,”vals”) has been used for creating a similar figure.
You can refer to the following documentation link for more information on the “subplot” function.:
Adam Danz
Adam Danz 2022년 10월 6일
Also consider turning on the "box" and using grid lines instead of using double labels.
plot(rand(5))
box on
grid on

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by