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

조회 수: 2 (최근 30일)
Francesco Marchione
Francesco Marchione 2024년 7월 31일
댓글: Francesco Marchione 2024년 7월 31일
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
Francesco Marchione
Francesco Marchione 2024년 7월 31일
Thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (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