Matlab散点图[副本]

w41d8nur  于 2023-04-21  发布在  Matlab
关注(0)|答案(1)|浏览(152)

此问题已在此处有答案

Matlab - Creating a heatmap to visualize density of 2D point data(2个答案)
8天前关闭
我有两列数据,x和y,我怎么用matlab做一个“热力学图”?我想用z轴代表点的强度,如下图所示。

X轴是速度,而Y轴是扭矩。我想构建一个像这样的热图,但带有点:

我尝试使用imagesc函数,但没有得到我想要的结果。示例代码:

x = rand(1373,1);
y = rand(1373,1);
z = rand(1373,1)*50;
scatter(w_mot,T_mot,z,'filled');
[Xi,Yi] = meshgrid(linspace(0,1,1000),linspace(0,1,1000));
SI = scatteredInterpolant(w_mot,T_mot,z);
Ci = SI(Xi,Yi);
xytpbqjk

xytpbqjk1#

解决方案/示例回答了您关于scatter-plot函数与colormap组合的问题,假设三个输入x,y,z或速度,扭矩和效率已知。即,以下值仅用于可视化目的。

x = randn(1373,1);   % using Normally distributed random numbers instead of uniformly
y = randn(1373,1);

z = sqrt(sum([x.^2 y.^2],2));   % calculate "density"
z = 1 - z./max(z);  % has to be normalized to 0...1

% cf. doc colormap
cmap = colormap("turbo");

% calculate a index for the color (depending on the value of normalized z)
% and ensure minimum has index 1 not zero
colIdx = max(floor(z * length(cmap)),1);

figure
scatter(x,y,20,cmap(colIdx,:),"filled")

对于不同的色彩Map,请参阅MathWorks doc

相关问题