【问题标题】:Why does FaceAlpha affect ZData of different object?为什么 FaceAlpha 会影响不同对象的 ZData?
【发布时间】:2015-08-04 06:55:23
【问题描述】:

在 linux 中使用 matlab 2015a。 尝试此代码(附带 mat 文件中的切片网格、x 和 y) FaveAlpha.mat

load('FaceAlpha.mat'); % Loading SliceGrid and X,Y parametrs
hold on; xlabel('X'), ylabel('Y'), zlabel('Z'); axis equal;
axis image; 
plot(SliceGrid.x(X),SliceGrid.y(Y),'blue.');hold on;
h=[-8 -0.5 0.5 1]
v=[7 4 4 7];
fill_2=fill(h,v,'blue'); % Creating blue object
x=[0 -0.5 0.5 1]
y=[9 4 4 9];
fill_1=fill(x,y,'red');% Creating red object
t=[-2 -0.5 0.5 2];
z=[9 2 2 0];
fill_3=fill(t,z,'yellow'); % Creating yellow object
set(fill_1,'FaceAlpha',0.5); % After this line everthing is ok.
set(fill_2, 'ZData', repmat(10, size(get(fill_2, 'XData')))); %  After this line the outside blue plot is damaged  - as you can see in the above figure
%%%%%%%%%%%% if we omit the  line ->  set(fill_1,'FaceAlpha',0.5);
%%%%%%%%%%%% and leave the code with the ZData property, the outside blue plot doesn't damaged.  
%%%%%%%%%%%% if we omit the  line ->  set(fill_2, 'ZData', repmat(10, size(get(fill_2, 'XData'))));
%%%%%%%%%%%% and leave the code with the FaceAlpha property, the outside blue plot doesn't damaged.

为什么以及如何使用 ZData 影响其他对象?为什么他们不一起工作?怎么了?谢谢!!

之前:

之后:

【问题讨论】:

  • 这是渲染器的问题。您对矢量渲染器画家好吗? ->set(gcf,'Renderer','painters')。除此之外,您还想对二维图中的 Z 数据做什么?您能否发布一张屏幕截图,说明它的外观以及您想要更改的内容?
  • HI @thewaywewalk 添加了屏幕截图
  • 好的,所以它在我的机器上看起来和我的机器上一样,特别让我想知道的是,蓝色补丁出现在前面。这是不希望的,是吗?那么painters的方式呢,你试过了吗?
  • 看来ZData之后的那行代码解决了问题-set(gca,'SortMethod','childorder')
  • 这是一个我以前从未使用过的有趣属性。您应该将其发布为答案。

标签: matlab matlab-figure


【解决方案1】:

好的,看来如果我们检查这行代码之后的代码:

set(fill_1,'FaceAlpha',0.5);
a=get(gca,'SortMethod')

我们会得到a=childorder,也就是说每个对象的出现都是按照图形的gca的子顺序(顺便说一下这是默认的) 在ZData的代码行之后,这个顺序被Matlab改变了,它改变了深度,所以如果你要重用这个函数:

a=get(gca,'SortMethod')

a=现在的深度。

因此,如果您想解决问题,只需使用以下代码:

set(gca,'SortMethod','childorder')

而且 - 我们有一个赢家! :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    • 2012-08-03
    • 2019-09-15
    • 1970-01-01
    • 1970-01-01
    • 2017-10-29
    • 2020-07-23
    相关资源
    最近更新 更多