MATLAB:同时使用scatter3和网格 [英] MATLAB: Using scatter3 and mesh at the same time

查看:339
本文介绍了MATLAB:同时使用scatter3和网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3d图,其中包含使用surf绘制的半球,我正尝试使用scatter3绘制更多数据.只要我传递给scatter3的数据集包含的点数不超过2000点,此方法就可以正常工作.如果有超过2000个点,则scatter3不会绘制任何内容.如果我删除了网上冲浪的电话,则scatter3会起作用并绘制数据.

I have a 3d plot that contains a hemisphere drawn using surf and I am trying to plot more data using scatter3. This works fine as long as the data set I pass to scatter3 contains no more than 2000 points. If there are more than 2000 points, then scatter3 does not plot anything. If I remove the call to surf, then scatter3 works and draws the data.

我已确认保留.我颠倒了surf和scatter3的调用顺序,但没有任何影响.我是否需要从scatter3切换到plot3(建议类似

I have verified that hold is on. I reversed the order of the calls to surf and scatter3 but it did not have any affect. Do I need to switch from scatter3 to plot3 (similar was suggested here) or is there some limit I can change for scatter3?

我正在使用Matlab 2012b.

I am using Matlab 2012b.

编辑:我做了一些进一步的挖掘,并调查了正在使用的渲染器.当我没有显示半透明的半球时,渲染器是"painters",但是添加半球会将渲染器更改为OpenGL.如果我强制渲染器为"painters"(使用set(gcf,'Renderer','painters'),则scatter3可以正常工作,但是我失去了半球的透明度.这是有道理的,但是我真的需要透明性,因为使用scatter3绘制的数据位于半球之内.添加第二个轴将无济于事,因为渲染器用于整个图形,而不是每个轴(对吗?)

EDIT: I did some more digging and looked into the renderers being used. When I do not have the semi-transparent hemisphere displayed, the renderer is "painters" but adding the hemisphere changes the renderer to OpenGL. If I force the renderer to be "painters" (using set(gcf, 'Renderer', 'painters') then scatter3 works properly but I lose the transparency on the hemisphere. This makes sense, but I really need the transparency because part of the data plotted using scatter3 is within the hemisphere. Adding a second axes will not help because the renderer is for the entire figure, not each axes (right?)

推荐答案

不幸的是,我认为解决方案"是Matlab中OpenGL渲染器中的错误.使用OpenGL渲染器时,如果颜色向量中的最后一个值为NaN,则Matlab将不会显示传递给scatter3的任何数据.不过,向量中的其他值可以是NaN.只要最后一个值为非NaN,scatter3支持的点数似乎就没有限制.

Unfortunately, I think the "solution" is a bug in the OpenGL renderer in Matlab. When using the OpenGL renderer, Matlab will not display any of the data passed to scatter3 if the last value in the color vector is NaN. Other values in the vector can be NaN, though. As long as the last value is non NaN, there does not appear to be a limit on the number of points supported by scatter3.

此代码工作调用具有2001个随机点的scatter3:

This code work calls scatter3 with 2001 random points:

myX = randi(300, 1, 2001)
myY = randi(300, 1, length(myX))
myZ = randi(300, 1, length(myX))
myColors = ones(1, length(myX))
[x,y,z] = sphere(10)

% Figure 1
figure
surf(x*50, y*50, z*50, 'FaceAlpha', 0.2, 'EdgeAlpha', 0.0, 'FaceColor', [1 0 0])
hold on
scatter3(myX, myY, myZ, 100, myColors, 'filled')

如果颜色矢量已更改,因此最后一个值为NaN,则生成的图将不包含任何scatter3数据

If the color vector is changed so the last value is NaN, the resulting plot does not contain any of the scatter3 data

myX = randi(300, 1, 2001)
myY = randi(300, 1, length(myX))
myZ = randi(300, 1, length(myX))
myColors = ones(1, length(myX))
[x,y,z] = sphere(10)

% Figure 1
figure
myColors = ones(1, length(myX))
myColors(1,length(myX)) = NaN;
surf(x*50, y*50, z*50, 'FaceAlpha', 0.2, 'EdgeAlpha', 0.0, 'FaceColor', [1 0 0])
hold on
scatter3(myX, myY, myZ, 100, myColors, 'filled')

看来,OpenGL渲染器不支持NaN作为颜色,而不是绘画器渲染器.如果逐行运行下一个示例,则可以看到OpenGL渲染器如何显示绘画渲染器未显示的点.

It also appears that the OpenGL renderer does not support NaN as a color the same way as the painters renderer. If you run this next example line by line, you can see how the OpenGL renderer displays points that were not displayed by the painters renderer.

myX = randi(300, 1, 10)
myY = randi(300, 1, length(myX))
myZ = randi(300, 1, length(myX))
myColors = ones(1, length(myX))
[x,y,z] = sphere(10)

% Figure 1
figure
myColors(1,1:5) = NaN;
scatter3(myX, myY, myZ, 100, myColors, 'filled')
get(gcf, 'Renderer')

% Figure 2
figure
myColors(1,1:5) = NaN;
scatter3(myX, myY, myZ, 100, myColors, 'filled')
get(gcf, 'Renderer')
hold on
surf(x*50, y*50, z*50, 'FaceAlpha', 0.2, 'EdgeAlpha', 0.0, 'FaceColor', [1 0 0])
get(gcf, 'Renderer')

我不会重写程序的大部分内容,而只是使用一个逻辑标记来基于颜色矢量中的NaN值来设置更新X矢量中的值

Rather than rewrite large parts of my program, I am just going to use a logical mark to set update the values in the X vector based on NaN values in the color vector

myX(isnan(myColors)) = NaN

画家和OpenGL渲染器似乎以相同的方式处理NaN.

The painters and OpenGL renderers appear to handle NaN as a location the same way.

希望这将对遇到与我一样的问题的人有所帮助.

Hopefully this will help someone who runs into the same issue I did.

这篇关于MATLAB:同时使用scatter3和网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆