【问题标题】:Change the color of a surface plot from SFIT in MATLAB从 MATLAB 中的 SFIT 更改曲面图的颜色
【发布时间】:2017-02-17 15:09:26
【问题描述】:

我有四个用于绘制的 SFIT 对象:

figure;
hold on;
plot(f1);
plot(f2);
plot(f3);
plot(f4);

这会绘制一个 3D 曲面。 但是我想给每个表面一种独特的颜色,就像它在绘图功能中很常见一样。通常这是通过提供参数 'r' 或指示颜色的东西来完成的,例如:

plot(f1,'r');

但是,如果我在这里执行此操作,我会收到以下错误:

使用绘图时出错 'r' 没有给出值。名称-值对参数 需要一个名称后跟一个值。

sfit/plot 中的错误>iParseInputs(第 231 行)p.parse( 参数值对{:});

sfit/plot 中的错误(第 44 行)[XY, Z, in, out, style, level, hParent] = iParseInputs(obj, varargin{:});

这表示必须给出一个字符串,但是哪个?我已经尝试过诸如“Color”或“LineColor”之类的东西,但这些都无法识别

问题的简化:我希望代表拟合对象的平面具有一种颜色。每架飞机都应该有不同的。

【问题讨论】:

    标签: matlab plot polynomials


    【解决方案1】:

    从此链接:

    https://uk.mathworks.com/matlabcentral/answers/153208-how-can-i-make-the-contour-plot-of-an-sfit-object-resemble-the-plot-generated-by-the-contour-com

    你可以试试

    f1 = fit([x y], z, 'poly23');
    ph = plot(f1, 'Style', 'Contour');
    set(ph, 'Fill', 'off', 'LineColor', 'auto');
    

    set 的文档

    https://uk.mathworks.com/help/matlab/ref/set.html


    编辑

    上述建议仅显示 2D 绘图,请参阅此之前针对 3D 案例的 SO 答案:

    MATLAB - Plot multiple surface fits in one figure

    你的相关代码是:

    figure; 
    h = plot(f1); 
    set(h(1),'FaceColor','r');
    

    所以你正在寻找的“神奇词”是'FaceColor',与set结合使用(如上所述)。

    【讨论】:

    • 感谢您的回答,但这并不是我想要的。首先使用 plot(f1, 'Style', 'Contour'),只导致一个 2D Plot,其中我有一个 3D-Plot。当简单地使用 plot(f1) - 所以绘图仍然是 3D 时,set 的函数调用会给出错误:“Surface 类上没有 Fill 属性”
    • 谢谢,这个链接有点矫枉过正,但我​​找到了正确的行,所以很简单:图; h = 情节(f1);设置(h(1),'FaceColor','r')。我不确定这个问题是否重复。但是,如果您可以在答案中插入该代码 sn-p 我会接受它。
    • @Kev1n91 我不认为这是重复的,因为您有一个更简单的请求,因此为了快速参考,更容易看到这个解决方案。我已经进行了编辑,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2012-10-05
    • 2013-12-11
    • 1970-01-01
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多