简体   繁体   English

Matlab:如何在plot3()函数中平滑矩阵的颜色?

[英]Matlab: How to smooth colors of matrix in plot3( ) function?

I am using plot3 to plot a matrix such that the resultant figure shows different colors for each vector of that matrix: 我正在使用plot3绘制矩阵,以便结果图为该矩阵的每个向量显示不同的颜色:

plot3(Grid.x1(:,:),Grid.x2(:,:),phi(:,:))

在此处输入图片说明

How can I smooth the coloring of this plot? 如何平滑该图的着色? Thanks! 谢谢!

You can use varycolor from FileExchange to construct and control a continuous range color spectrum. 您可以使用FileExchange中的variantcolor来构建和控制连续范围的色谱。 This way the transition between different lines will seem more natural and proximal lines will have similar colors. 这样,不同线条之间的过渡看起来会更自然,而近端线条将具有相似的颜色。

You can read more and see examples usage here http://blogs.mathworks.com/pick/2008/08/15/colors-for-your-multi-line-plots/ 您可以在此处阅读更多内容并查看示例用法http://blogs.mathworks.com/pick/2008/08/15/colors-for-your-multi-line-plots/

Example : 范例

[X,Y,Z] = peaks(128);

% raw plot3()
figure; plot3(X, Y, Z); 

在此处输入图片说明

% define set equal to line number
ColorSet = varycolor(128);

% smooth plot3()
figure; hold all;
set(gca, 'ColorOrder', ColorSet);
plot3(X, Y, Z); view(3); 

在此处输入图片说明

Update : For a continuous 3D plot (ie a surface) you can use surfl instead of plot3 and display your data as a 3-D Surface Plot (with Shading) . 更新 :对于连续的3D图(即表面),您可以使用surfl代替plot3并将数据显示为3-D 表面图(带有阴影) You can additionally apply any colormap on the resulting surface, ie gray or ColorSet as above. 您还可以在结果表面上应用任何colormap ,即如上所述的grayColorSet

surfl(X,Y,Z);
shading interp;
colormap(gray); 

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM