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

2 views (last 30 days)
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!

Accepted Answer

Harsh
Harsh on 31 Jul 2024
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 Comments
Harsh
Harsh on 31 Jul 2024
@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

Sign in to comment.

More Answers (0)

Categories

Find more on Formatting and Annotation in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!