MATLAB streamribbon边缘颜色 [英] MATLAB streamribbon edge color

查看:111
本文介绍了MATLAB streamribbon边缘颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在流形图中,如何绘制色带本身的边缘,而不是每个面的边缘?

In a streamribbon plot, how do you plot the edges of the ribbon itself, as opposed to the edges of every face?

例如:

figure
load wind
[sx sy sz] = meshgrid(80,20:10:50,0:5:15);
h = streamribbon(x,y,z,u,v,w,sx,sy,sz);
axis tight
shading interp;
view(3);
camlight
lighting gouraud

产生:

如果我添加 set(h,'edgecolor','k')

我得到:

而我正在寻找的是这样的东西(图像的顶部和左侧已经用 gimp 进行了编辑,以表明我正在追逐的内容):

Whereas what I'm looking for is something like this (top and left sides of image have been edited with gimp, to make the point of what I'm chasing):

推荐答案

如评论中所述,没有简单的方法来照亮色带表面的某些边缘,而不能照亮其他表面.

As said in the comment, there is no easy way to illuminate some edges of the ribbon surfaces and not other.

但是,功能区表面仅由边缘上的点定义,因此只需获取这些点并重新组织(内联)它们即可为3D线获得完美的坐标集.
要获取已关闭的配置文件,我们只需要在配置文件的末尾复制第一个点即可.

However, the ribbon surfaces are simply defined by the points on the edges, so it is only a matter of retrieving these points and reorganizing them (inline them) to get a perfect coordinate set for 3D lines.
To get a closed profile, we just need to replicate the first point at the end of the profile.

我将其打包到一个函数中,该函数将返回与功能区句柄数组大小相同的一组 handles ,并将可以发送给内部 plot3 功能.因此用法非常简单:

I packaged that into a function which will return a set of handles the same size as the ribbon handle array, and transfer any additional parameters you can send to the internal plot3 function. So the usage is quite straightforward:

因此,使用与问题完全相同的代码(在变量 h 中检索色带表面手柄的数组),并添加:

So using exactly the same code than in the question (which retrieve the array of ribbon surface handle in the variable h), adding:

hs = StreamEdges( h , 'k','Linewidth',1 ) ;

将产生:

当然,您总是可以抓狂并在组中设置线路属性:

Of course, you can always get crazy and set your line properties in group:

set(hs,'LineWidth',1,'Color','c')
%// or
set(hs,'LineWidth',2,'Color','r','Marker','none')

函数 StreamEdges.m 的代码:

Code for function StreamEdges.m :

function hs = StreamEdges(hribbon,varargin)

wasOnHold = ishold ;            %// save hold state
hold on

hs = zeros( size(hribbon) ) ;   %// initialize output handle array
for ih=1:numel( hribbon ) ;
    %// retrieve X, Y, and Z data of each surface
    hsurf = handle( hribbon(ih)) ;  %// for pre-HG2 (2014a) versions
    xx = hsurf.XData ;
    yy = hsurf.YData ;
    zz = hsurf.ZData ;

    %// reoder coordinates to linearise surface profile (edge)
    xx = [xx(:,1) ; flipud(xx(:,2)) ; xx(1)] ;
    yy = [yy(:,1) ; flipud(yy(:,2)) ; yy(1)] ;
    zz = [zz(:,1) ; flipud(zz(:,2)) ; zz(1)] ;

    %// return double to stay compatible with pre-HG2
    hs(ih) = double( plot3(xx(:),yy(:),zz(:), varargin{:} ) ) ;
end

if ~wasOnHold ; hold off ; end      %// restore hold state
hs = handle(hs) ;                   %// convert "double" handle back to HG2 handles


该功能应与HG2之前的版本(= 2014b之前)或HG2以后的版本一起使用.它返回的句柄数组将为HG2格式(=实际句柄,而不仅仅是它们的 double 表示形式).这样,即使对于HG2之前的版本,您也可以访问图形对象上的点符号.如果您对此不满意,只需在函数的最后一行添加注释(,或者要获取旧的句柄样式,您始终可以使用函数 hs = double(hs))


The function should work with version pre-HG2 (=pre 2014b) or post-HG2. The handle array it will return will be in the HG2 format (= real handle, not just their double representation). This gives you access to the dot notation on your graphic object even for version pre-HG2. If you are not comfortable with that, just comment the last line of the function (or to get the old handle style you can always use the function hs = double(hs))

目标

Target axes

除了保留 hold 状态外,该功能的行为类似于大多数高级绘图功能,这意味着它们将直接转到当前的 axes (gca ),或者如果不存在则创建一个新的.
您可以轻松地修改该函数以接受 axes 句柄作为目标,或者简单地进行修改,而无需在参数中明确调用它:

Apart from the preservation of the hold state, the function will behave like most high level plot function, meaning they will go directly to the current axes (gca), or create a new one if none exist.
You can easily modify the function to accept an axes handle as target, or simply without modification, call it explicitly in the parameters:

hs = StreamEdges( h , 'Parent','target_axes_handle' , 'Color','k','Linewidth',1) ;

这篇关于MATLAB streamribbon边缘颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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