Plot values on a x-y plane from excel - with colorbar

2 次查看(过去 30 天)
I would like to plot a x-y values from the excel attached on a plane.
I need a colorbar and Latex font.
Thanks everyone!

采纳的回答

Harsh
Harsh 2024-7-31
From what can be gathered, you are trying to plot x and y coordinates using the points mentioned in the Excel file along with a bicubic interpolation between values. Here’s how to do it along with adding a relevant colormap:
T = readtable("Values.xlsx");
x = T.x
y = T.y
z = T.value
% Create a grid for interpolation
[Xq, Yq] = meshgrid(linspace(min(x), max(x), 100), linspace(min(y), max(y), 100));
% Interpolate z values on the grid
Zq = griddata(x, y, z, Xq, Yq, 'cubic');
% Create the surface plot
figure;
surf(Xq, Yq, Zq, 'EdgeColor', 'none');
% Add colorbar
colorbar;
% Set colormap
colormap jet;
% Set LaTeX font for axes labels and title
xlabel('X-axis', 'Interpreter', 'latex');
ylabel('Y-axis', 'Interpreter', 'latex');
zlabel('Z-axis', 'Interpreter', 'latex');
title('Sample 3D Surface Plot with Bicubic Interpolation', 'Interpreter', 'latex');
% Optionally, set LaTeX font for ticks
set(gca, 'TickLabelInterpreter', 'latex');
Here’s the expected result:
I hope this helps, thanks!
  3 个评论
Harsh
Harsh 2024-7-31
@Francesco Marchione, you can do that using the "imagesc" function, here's the updated snippet of code for the same:
% Create a grid for interpolation
[Xq, Yq] = meshgrid(linspace(min(x), max(x), 100), linspace(min(y), max(y), 100));
% Interpolate z values on the grid
Zq = griddata(x, y, z, Xq, Yq, 'cubic');
% Create the 2D plot using imagesc
figure;
imagesc(linspace(min(x), max(x), 100), linspace(min(y), max(y), 100), Zq);
axis xy; % Ensure the y-axis is oriented correctly
% Add colorbar
colorbar;
% Set colormap
colormap jet;
% Set LaTeX font for axes labels and title
xlabel('X-axis', 'Interpreter', 'latex');
ylabel('Y-axis', 'Interpreter', 'latex');
title('Sample 2D Plot with Bicubic Interpolation', 'Interpreter', 'latex');
% Optionally, set LaTeX font for ticks
set(gca, 'TickLabelInterpreter', 'latex');
Here, I have attached the expected result:
To learn more about the "imagesc" function feel free to checkout the following documentation:
https://www.mathworks.com/help/matlab/ref/imagesc.html

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Formatting and Annotation 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by