How to check if right axis is visible?

9 ビュー (過去 30 日間)
Micke Malmström
Micke Malmström 2016 年 9 月 27 日
編集済み: Oli Fairfax 2023 年 8 月 4 日
I have a finction that process all the lines in the current graph. Since the introduction of
yyaxis right
I need my function to be able to figure out if the right axis is visible or not.
If I just run
yyaxis right
then I cant check if it is visible because the command will invoke the right axis to appear. Anny suggestions?
  2 件のコメント
KSSV
KSSV 2016 年 9 月 27 日
編集済み: KSSV 2016 年 9 月 27 日
I guess you have to check the handles..have you tried checking handles?
José-Luis
José-Luis 2016 年 9 月 27 日
編集済み: José-Luis 2016 年 9 月 27 日
According to the documention yyaxis wil create a secondary y-axis if none exists. The good people at TMW don't want you tinkering with yyaxis so they made it a p-file and you can't change the default behavior.
So my suggestion would be not to use yyaxis at all and instead create the axes yourself and keep track of the handles.

サインインしてコメントする。

回答 (2 件)

Adam
Adam 2016 年 9 月 27 日
function isVisible = isYAxisVisibleAtLocation( hAxes, location )
assert( isgraphics( gca, 'axes' ) );
location = validatestring( location, { 'left', 'right' } );
isVisible = strcmp( hAxes.YAxisLocation, location );
isVisible = isVisible | numel( hAxes.YAxis ) == 2;
end
This should do the job, if you give it your axes handle (which it is good practice to always keep hold of, but you can get hold of it if you don't have it anyway) and either 'left' or 'right'.
You could beef up the validation a bit as I usually would, but I just did a minimal amount here.

Oli Fairfax
Oli Fairfax 2023 年 8 月 4 日
編集済み: Oli Fairfax 2023 年 8 月 4 日
I just use the length of the YAxis property - if it's lenght = 1, there is only a single (left) axis, if length = 2, there is also a right hand axis.
if length(axes.YAxis) == 2
isYYaxis = true;
else
isYYaxis = false;
end

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by