'yyaxis' 轴属性的行为
Behaviour of axis properties with 'yyaxis'
创建一个有两个 y 轴的图形,使用 yyaxis
:
figure
yyaxis left
hl = plot([0 10],[0 10],'-');
yyaxis right
hr = plot([0 10],[10 0],'--');
已发现以下奇怪行为。这已经在 Windows 10.
的 R2017b 和 R2019a 中进行了测试
对象hl
和hr
似乎属于同一个轴(即yyaxis
不创建新轴):
>> get(hr, 'parent')==get(hl, 'parent')
ans =
logical
1
但是轴的'children'
属性只反映了一个对象:
>> get(get(get(hl, 'parent'), 'children'), 'LineStyle')
ans =
'--'
>> get(get(get(hr, 'parent'), 'children'), 'LineStyle')
ans =
'--'
此外,父轴的 YAxisLocation'
属性 对两个对象具有 相同的值:
>> get(get(hl, 'parent'), 'YAxisLocation')
ans =
'right'
>> get(get(hr, 'parent'), 'YAxisLocation')
ans =
'right'
如果我们现在点击实线,使其成为当前对象,
>> 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'
同样,如果我们现在点击虚线,
>> 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')
行为类似:仅列出最后绘制的对象或已成为当前对象的对象。
以上行为可以总结如下:
- 只有 一个 轴(并且所有对象的
'parent'
属性 都指的是那个轴,正如预期的那样)。
- 轴的
'children'
属性只列出一个对象,即当前对象,或者上次绘制的对象
- 轴的
'YAxisLocation'
属性在'left'
和'right'
之间动态变化。同样,这由当前对象或最后绘制的对象决定。
不清楚如何理解这种行为。以下问题自然会出现:
- 这在某处记录了吗?
- 怎么可能两个物体有同一个轴
'parent'
,而那个轴只有当前物体'children'
?
- 为什么
'YAxisLocation'
也会根据当前对象的不同而变化?
在我看来,yyaxis
在幕后做了一些令人讨厌的事情,并且有很多我们无法访问的隐藏数据。
documentation 确实是这样说的:
yyaxis left
activates the side of the current axes associated with the left y-axis. Subsequent graphics commands target the left side.
和
The Children
property of the Axes
object only contains the children for the active side. To access all the children for both sides, use the allchild
function.
将 "side" 更改为 yyaxis
因此会更改 Axes
对象的内容,我假设另一侧的内容存储在我没有的某个隐藏位置'无法找到。 yyaxis
是 P 代码,所以我们无法弄清楚它到底在做什么。
这很有趣:
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
代码创建了具有不同限制的左右轴。我们得到坐标轴的句柄,向左移动,从句柄读取限制,然后向右移动并再次读取相同的 属性。第一次是returns[0,1]
,第二次是[0,100]
。也就是说,当我们调用 yyaxis
.
时,具有句柄 h
的 Axes
对象发生了变化
我发现 h
指向具有两侧的轴的唯一迹象是 h.YAxis
returns 两个指向 NumericRuler
对象的句柄,每侧一个.
我不禁觉得这是一种尴尬的行为。我原以为会有两个 Axes
对象,它们都具有相同的 Position
属性,并且可能具有使两者保持同步的侦听器。
创建一个有两个 y 轴的图形,使用 yyaxis
:
figure
yyaxis left
hl = plot([0 10],[0 10],'-');
yyaxis right
hr = plot([0 10],[10 0],'--');
已发现以下奇怪行为。这已经在 Windows 10.
的 R2017b 和 R2019a 中进行了测试对象hl
和hr
似乎属于同一个轴(即yyaxis
不创建新轴):
>> get(hr, 'parent')==get(hl, 'parent')
ans =
logical
1
但是轴的'children'
属性只反映了一个对象:
>> get(get(get(hl, 'parent'), 'children'), 'LineStyle')
ans =
'--'
>> get(get(get(hr, 'parent'), 'children'), 'LineStyle')
ans =
'--'
此外,父轴的 YAxisLocation'
属性 对两个对象具有 相同的值:
>> get(get(hl, 'parent'), 'YAxisLocation')
ans =
'right'
>> get(get(hr, 'parent'), 'YAxisLocation')
ans =
'right'
如果我们现在点击实线,使其成为当前对象,
>> 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'
同样,如果我们现在点击虚线,
>> 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')
行为类似:仅列出最后绘制的对象或已成为当前对象的对象。
以上行为可以总结如下:
- 只有 一个 轴(并且所有对象的
'parent'
属性 都指的是那个轴,正如预期的那样)。 - 轴的
'children'
属性只列出一个对象,即当前对象,或者上次绘制的对象 - 轴的
'YAxisLocation'
属性在'left'
和'right'
之间动态变化。同样,这由当前对象或最后绘制的对象决定。
不清楚如何理解这种行为。以下问题自然会出现:
- 这在某处记录了吗?
- 怎么可能两个物体有同一个轴
'parent'
,而那个轴只有当前物体'children'
? - 为什么
'YAxisLocation'
也会根据当前对象的不同而变化?
在我看来,yyaxis
在幕后做了一些令人讨厌的事情,并且有很多我们无法访问的隐藏数据。
documentation 确实是这样说的:
yyaxis left
activates the side of the current axes associated with the left y-axis. Subsequent graphics commands target the left side.
和
The
Children
property of theAxes
object only contains the children for the active side. To access all the children for both sides, use theallchild
function.
将 "side" 更改为 yyaxis
因此会更改 Axes
对象的内容,我假设另一侧的内容存储在我没有的某个隐藏位置'无法找到。 yyaxis
是 P 代码,所以我们无法弄清楚它到底在做什么。
这很有趣:
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
代码创建了具有不同限制的左右轴。我们得到坐标轴的句柄,向左移动,从句柄读取限制,然后向右移动并再次读取相同的 属性。第一次是returns[0,1]
,第二次是[0,100]
。也就是说,当我们调用 yyaxis
.
h
的 Axes
对象发生了变化
我发现 h
指向具有两侧的轴的唯一迹象是 h.YAxis
returns 两个指向 NumericRuler
对象的句柄,每侧一个.
我不禁觉得这是一种尴尬的行为。我原以为会有两个 Axes
对象,它们都具有相同的 Position
属性,并且可能具有使两者保持同步的侦听器。