本文介绍了轴属性与"yyaxis"的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 yyaxis :

figure
yyaxis left
hl = plot([0 10],[0 10],'-');
yyaxis right
hr = plot([0 10],[10 0],'--');

已发现以下奇怪行为.已在Windows 10的R2017b和R2019a中进行了测试.

The following curious behaviour has been found. This has been tested in R2017b and in R2019a on Windows 10.

对象hlhr似乎属于相同轴(即yyaxis不会创建新轴):

The objects hl and hr seem to belong to the same axis (that is, yyaxis does not create a new axis):

>> get(hr, 'parent')==get(hl, 'parent')
ans =
  logical
   1

但是,轴'children'属性仅反映一个对象:

However, the 'children' property of the axis only reflects one object:

>> get(get(get(hl, 'parent'), 'children'), 'LineStyle')
ans =
    '--'
>> get(get(get(hr, 'parent'), 'children'), 'LineStyle')
ans =
    '--'

此外,父轴的YAxisLocation'属性对于两个对象都具有相同的:

Also, the YAxisLocation' property of the parent axis has the same value for both objects:

>> get(get(hl, 'parent'), 'YAxisLocation')
ans =
    'right'
>> get(get(hr, 'parent'), 'YAxisLocation')
ans =
    'right'

如果我们现在单击实线,使其成为当前对象,

If we now click on the solid line, to make it the current object,

>> get(get(get(gco, 'parent'), 'children'), 'LineStyle')
ans =
    '-'
>> get(get(get(hl, 'parent'), 'children'), 'LineStyle')
ans =
    '-'
>> get(get(get(hr, 'parent'), 'children'), 'LineStyle')
ans =
    '-'
>> get(get(gco, 'parent'), 'YAxisLocation')
ans =
    'left'

类似地,如果我们现在单击虚线,

Similarly, if we now click on the dotted line,

>> get(get(get(gco, 'parent'), 'children'), 'LineStyle')
ans =
    '--'
>> get(get(get(hl, 'parent'), 'children'), 'LineStyle')
ans =
    '--'
>> get(get(get(hr, 'parent'), 'children'), 'LineStyle')
ans =
    '--'
>> get(get(gco, 'parent'), 'YAxisLocation')
ans =
    'right'

作为支票,

>> get(gcf, 'children')

也只给出一个轴,

>> get(get(gcf, 'children'), 'children')

的行为类似:仅列出最后绘制的对象,或者已使该对象成为当前对象.

behaves similarly: only the object that was plotted last, or thas has been made current, is listed.

上述行为可以总结,如下所示:

The above behaviour can be summarized as follows:

目前尚不清楚如何理解这种行为.自然会出现以下问题:

It's not clear how to make sense of this behaviour. The following questions naturally arise:

推荐答案

在我看来,yyaxis进行了一些令人讨厌的幕后操作,并且有许多我们无法访问的隐藏数据.

To me it looks like yyaxis does some nasty-behind-the-scenes things and there's lots of hidden data we can't access.

文档确实表示:

yyaxis更改面"因此会更改Axes对象的内容,我认为另一面的内容存储在我无法找到的某个隐藏位置中. yyaxis是P代码,所以我们无法弄清楚它到底在做什么.

Changing the "side" with yyaxis therefore changes the contents of the Axes object, I presume that the contents for the other side gets stored in some hidden location that I haven't been able to find. yyaxis is P-code, so we won't be able to figure out what exactly it is doing.

这很有趣:

figure
yyaxis left
hl = plot([0 10],[0 1],'-');
yyaxis right
hr = plot([0 10],[100 0],'--');

h = gca;

yyaxis left
h.YLim

yyaxis right
h.YLim

该代码创建具有不同限制的左轴和右轴.我们将手柄置于轴上,向左更改,从手柄上读取限制,然后向右更改并再次读取相同的属性.第一次返回[0,1],第二次返回[0,100].也就是说,当调用yyaxis时,带有句柄hAxes对象会更改.

The code creates left and right axes with different limits. We get the handle to the axes, change to left, read the limits from the handle, then change to right and read the same property again. The first time it returns [0,1], the second time it is [0,100]. That is, the Axes object with handle h changes when we call yyaxis.

我发现h指向具有两侧的轴的唯一指示是h.YAxis返回两个NumericRuler对象的句柄,每侧一个.

The only indication I've found that h points to axes with two sides is that h.YAxis returns two handles to NumericRuler objects, one for each side.

我不能不觉得这是尴尬的行为.我本来希望有两个Axes对象,两个对象都具有相同的Position属性,并且可能具有使两个对象保持同步的侦听器.

I can't but feel this is awkward behavior. I would have expected there to be two Axes objects, both with the same Position property, and maybe with listeners that keep the two in sync.

这篇关于轴属性与"yyaxis"的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:47