我想制作一个等高线/曲面图,它显示单元格中的值,类似于 EFI 调整图

问题描述 投票:0回答:2

我想在 MATLAB 中做这样的事情。这是一张地图,其中包含

x
y
轴以及
z
轴的值,并用颜色表示
z
值的大小。基本上是一个计数图,它在屏幕上打印矩阵中的值

示例图:

matlab matrix plot contour surface
2个回答
1
投票

修改
imagesc()
绘图

通过修改带有文本注释的

imagesc
图和
line()
函数来创建网格,这可能是足够相似的。需要完成一些轴属性(包括轴替换)才能正确配置绘图。不幸的是,这不是一种非常简洁的方法,但它可能会满足您的应用程序。

Engine_Load = [0.35 0.55 0.7 0.87 1 1.15 1.25 1.35 1.45 1.6 1.7 1.8 2 2.2 2.5];
Engine_Speed = (800:400:7600);

%Creating random test data%
[Engine_Load_Grid,Engine_Speed_Grid] = meshgrid(Engine_Load,Engine_Speed);
Estimated_Air_Fuel_Ratio = rand(length(Engine_Speed),length(Engine_Load));

%Creating the grid structure%
X_Axis = (1:length(Engine_Load));
Y_Axis = (1:length(Engine_Speed));
[X_Grid,Y_Grid] = meshgrid(X_Axis,Y_Axis);

clf;
imagesc('XData',X_Axis,'YData',Y_Axis,'CData',Estimated_Air_Fuel_Ratio);
xticks(1:1:length(X_Axis));
yticks(1:1:length(Y_Axis));
xlim([0.5 length(X_Axis)+0.5]);
ylim([0.5 length(Y_Axis)+0.5]);
Current_Axis = gca;
Current_Axis.XAxisLocation = 'Top';
grid on;

for Horizontal_Lines = 1: length(yticks)
line([0.5 length(X_Axis)+0.5],[Horizontal_Lines+0.5 Horizontal_Lines+0.5],'color','w','LineWidth',2);
end

for Vertical_Lines = 1: length(yticks)
line([Vertical_Lines+0.5 Vertical_Lines+0.5],[0.5 length(Y_Axis)+0.5],'color','w','LineWidth',2);
end

Estimated_Air_Fuel_Ratio = flip(Estimated_Air_Fuel_Ratio);
[Matrix_Height,Matrix_Width] = size(Estimated_Air_Fuel_Ratio);
for Row_Index = 1: Matrix_Height
    for Column_Index = 1: Matrix_Width
        
    text(Column_Index,Matrix_Height+1-Row_Index,num2str(Estimated_Air_Fuel_Ratio(Row_Index,Column_Index)));
    
    end
end

Current_Figure = gcf;
set(findall(gcf,'type','text'),'HorizontalAlignment','center')
set(Current_Axis,'xtick',X_Axis,'xticklabel',Engine_Load);
set(Current_Axis,'ytick',Y_Axis,'yticklabel',Engine_Speed);
xlabel('Engine Load'); ylabel('Engine Speed');
colorbar

Current_Figure.Position = [0 0 1000 1000];

使用 MATLAB R2019b 运行


0
投票

这是使用 surf R2024 的替代方案:

网格图示例

function gridplot(x, y, V, varargin)
%Display values as grid with color and text values.
%  gridplot(x, y, V)
%Example:
% gridplot(["Joe" "Bob"], [2 7 5], randi(20, 3, 2))
hold on, axis equal tight % Prepre axis
surf(0:numel(x), 0:numel(y), zeros(numel(y)+1, numel(x)+1), 'CData', V, 'EdgeColor', 'w', 'LineWidth', 3, varargin{:}) % Display grid
set(gca, 'XTick', 0.5:numel(x), 'XTickLabel', x) % Set x tick marks 
set(gca, 'YTick', 0.5:numel(y), 'YTickLabel', y) % Set y tick marks
set(gca, 'XAxisLocation', 'top', 'YDir','reverse') % Change axis location
[X, Y] = ndgrid(0.5:numel(x), 0.5:numel(y)); % Text locations
text(X(:), Y(:), V+"", 'HorizontalAlignment', 'center'); % Show text
© www.soinside.com 2019 - 2024. All rights reserved.