How to access second axes in the PLOTYY syntax?

조회 수: 2 (최근 30일)
balandong
balandong 2017년 10월 12일
댓글: balandong 2017년 10월 13일
Dear all,
This thread is a continuation from the following thread_1. Thanks to Walter for suggesting the code in the thread.
The idea was to add different XTickLabel at the second axes (i.e., ax(2)), specifically to change the label at the bottom X-axis into a set of number. I tried to access the second axis by plugging ax(2), but nothing is changing!.
Similarly, I want to add more instead of default one thicklabel at the second Y-axis. I assume, this too can be done by accessing the second axis.
Here is the code and some illustrative figure to show the intended objective.
Figure
ax = plotyy(st_X_hour, st_Vec_Y1_mean, st_X_hour, st_Y2, @(x,y) errorbar(x, y, st_Vec_Y1_Sd, '--x', 'MarkerSize', 15), @(x,y) plot(x, y, 'k') );
set(ax(1), 'Xtick', st_Xaxis_intrmit, 'XTickLabel',st_XLabel,'XAxisLocation','top');
xtickangle(ax(1), 90);
ylim(ax(1),[0.5 5.5])
nox=273:20:400;
set(ax(2), 'Xtick', nox, 'XTickLabel',1:numel(nox),'XAxisLocation','bottom');
Thanks in advance!

답변 (1개)

per isakson
per isakson 2017년 10월 13일
편집: per isakson 2017년 10월 13일
plotyy returns a vector of two axis-handles. (The diagram (before HG2 and I guess in HG2) was two plots on top of each other.)
>> ax = plotyy( (1:3), ones(1,3), (1:3),2*ones(1,3))
ax =
1x2 Axes array:
Axes Axes
>> ax(1)
ans =
Axes with properties:
XLim: [1 3]
YLim: [0 2]
XScale: 'linear'
YScale: 'linear'
GridLineStyle: '-'
Position: [0.1300 0.1100 0.7750 0.8150]
Units: 'normalized'
Show all properties
>> struct(ax(1))
Warning: ....
ans =
CameraPosition: [2 1 17.3205]
CameraPositionMode: 'auto'
CameraPosition_I: [2 1 17.3205]
CameraTarget: [2 1 0]
CameraTargetMode: 'auto'
CameraTarget_I: [2 1 0]
CameraUpVector: [0 1 0]
.............
And with a tool under development
>> dbnv( ax(1), 'YTick' )
YTick: [0 0.5000 1 1.5000 2]
YTick_I: [0 0.5000 1 1.5000 2]
YTickLabel: {5x1 cell}
YTickLabel_I: {5x1 cell}
YTickLabelMode: 'auto'
YTickLabelRotation: 0
YTickLabelRotation_I: 0
YTickLabelRotationMode: 'auto'
YTickLabels: {5x1 cell}
YTickLabels_I: {5x1 cell}
YTickLabelsMode: 'auto'
YTickMode: 'manual'
I'll first fix a problem, then I attach the function, dbnv
  댓글 수: 2
per isakson
per isakson 2017년 10월 13일
편집: per isakson 2017년 10월 13일
Here is the function, dbnv. It spits out a warning despite I have set the warning off.
The EraseMode property is no longer supported and will error in a future release.
id =
MATLAB:hg:EraseModeIgnored
>> dbnv( ax(1), 'YTick' )
85 opc = warning_off({
Warning: The DrawMode property will be removed in a future release. Use the SortMethod property instead.
> In dbnv>struct_array_ (line 134)
In dbnv (line 91)
Warning: The DrawMode property will be removed in a future release. Use the SortMethod property instead.
> In dbnv>struct_array_ (line 137)
In dbnv (line 91)
>> warning('query', 'MATLAB:hg:EraseModeIgnored' )
The state of warning 'MATLAB:hg:EraseModeIgnored' is 'off'.
balandong
balandong 2017년 10월 13일
Hi Per, Thanks for the reply. I tried to change the bottom X-axis with the following code, but I cant see any changes. I am using 2017a. In addition, I am still vague on how to use the DBNV function. Really appreciate if you can shed some light.
Thank you
ax = plotyy(st_X_hour, st_Vec_Y1_mean, st_X_hour, st_Y2, @(x,y) errorbar(x, y, st_Vec_Y1_Sd, '--x', 'MarkerSize', 15), @(x,y) plot(x, y, 'k') );
set(ax(1), 'Xtick', st_Xaxis_intrmit, 'XTickLabel',st_XLabel,'XAxisLocation','top');
xtickangle(ax(1), 90);
ylim(ax(1),[0.5 5.5])
set(ax(2),'XAxisLocation','bottom');
ax(2).XTick = [200 300];
ax(2).XTickLabel = [200 300];

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

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by