gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 19:06:24 25 4
gpt4 key购买 nike

我有一些数据(两个参数的函数)以 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com