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

2 vues (au cours des 30 derniers jours)
Francesco Marchione
Francesco Marchione le 31 Juil 2024
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!
  1 commentaire
Francesco Marchione
Francesco Marchione le 31 Juil 2024
with a bicubic interpolation between values

Connectez-vous pour commenter.

Réponse acceptée

Harsh
Harsh le 31 Juil 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 commentaires
Harsh
Harsh le 31 Juil 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
Francesco Marchione
Francesco Marchione le 31 Juil 2024
Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Formatting and Annotation dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by