matlab - 如何在 matlab 中绘制 "color map"图?

标签 matlab plot

我有一些数据(两个参数的函数)以 matlab 格式存储,我想用 matlab 绘制它。读入数据后,我使用 mesh() 绘制图表。我的 mesh() 绘图以颜色和表面高度的形式给出了函数值,如下所示:

A color and a surface height as a function of two independent variables.

我应该使用什么 matlab 绘图函数来制作 2D 网格图,其中因变量表示为仅一种颜色?我在 gnuplot 中寻找类似 pm3d map 的东西。

最佳答案

默认情况下,mesh 将根据(默认)jet 颜色图(即热度更高)为表面值着色。您还可以使用 surf 填充表面补丁并将 'EdgeColor' 属性设置为 'None'(因此补丁边缘不可见).

[X,Y] = meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;

% surface in 3D
figure;
surf(Z,'EdgeColor','None');

enter image description here

二维 map :可以通过切换图形的view属性得到二维 map

% 2D map using view
figure;
surf(Z,'EdgeColor','None');
view(2);    

enter image description here

... 或将 Z 中的值视为矩阵,使用 imagesc 将其视为缩放图像并选择适当的 colormap .

% using imagesc to view just Z
figure;
imagesc(Z); 
colormap jet; 

enter image description here

map 的颜色托盘由 colormap(map) 控制,其中 map 可以是自定义的,也可以是 MATLAB 提供的任何内置颜色图:

enter image description here

更新/细化 map : map 上的多个设计选项(分辨率、平滑度、轴等)可以通过常规 MATLAB 选项进行控制。正如@Floris 指出的那样,这是一个平滑的、等轴的、无轴标签的 map ,适用于这个例子:

figure;
surf(X, Y, Z,'EdgeColor', 'None', 'facecolor', 'interp');
view(2);
axis equal; 
axis off;

enter image description here

关于matlab - 如何在 matlab 中绘制 "color map"图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15754459/

相关文章:

MATLAB : How to build 4d plot per levels

python - pandas:绘制 DataFrame 时未显示 MultiIndex

matlab - 为什么 sum(X, 1) 是 MATLAB 中列的总和?

matlab - 如何为伪随机数生成器设置自定义种子

python - 为什么 MATLAB 在使用 "from tensorflow import keras"调用 python 脚本时会产生错误?

r - 使用 ggplot2 facet wrap R 控制图表

plot - 从数据文件读取的 gnuplot 标签中的上标/下标

python - 索引错误: list index out of range - when plotting images

matlab - 避免 MATLAB 图形中的文本重叠

java - 覆盖 MATLAB 默认静态 javaclasspath 的最佳方法