【问题标题】:Matlab how to change contourf plot's location on z axisMatlab如何改变轮廓图在z轴上的位置
【发布时间】:2023-03-24 03:57:01
【问题描述】:

我的图中有一个 3d 表面 surf(x,y,z)

我还有一个contourf 表面(基本上是一个二维平面)。

我将它们绘制在同一个图中,但contourf 绘图自动位于z=0 级别。我想将contourf 绘图移动到z=-10(或z 轴上的任何值),但我做不到。

我确信这很容易,但我在 MATLAB 帮助/Google 中找不到答案。 有什么想法吗?

【问题讨论】:

    标签: matlab 3d plot z-axis


    【解决方案1】:

    考虑以下示例:

    %# plot surface and contour
    Z = peaks;
    surf(Z), hold on
    [~,h] = contourf(Z);       %# get handle to contourgroup object
    
    %# change the ZData property of the inner patches
    hh = get(h,'Children');    %# get handles to patch objects
    for i=1:numel(hh)
        zdata = ones(size( get(hh(i),'XData') ));
        set(hh(i), 'ZData',-10*zdata)
    end
    


    更新:

    上述内容在 HG2 中不再有效。可以使用轮廓的隐藏属性来修复它ContourZLevel

    Z = peaks;
    surf(Z), hold on
    [~,h] = contourf(Z);
    h.ContourZLevel = -10;
    

    您也可以使用hgtransform 来实现类似的事情,这是记录和推荐的方法。

    请参阅我的另一个答案以获得进一步的解释:plot multiple 2d contour plots in one 3d figure

    【讨论】:

    • 如果你讨厌循环,可以将最后一部分改写成一行:set(hh, {'ZData'}, cellfun(@(x) -10*ones(size(x)), get(hh,{'XData'}), 'UniformOutput',false))
    • 优秀。多谢。我只需要了解更多关于对象以及如何使用 get 和 set 来“检查”和“更改”我喜欢的东西。除了 Matlab Help 之外,您还知道任何好的参考/教程吗?
    • @Amro 不错。这肯定会派上用场。
    猜你喜欢
    • 2018-11-30
    • 1970-01-01
    • 1970-01-01
    • 2017-10-07
    • 1970-01-01
    • 2016-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多