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
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
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 Center および File Exchange で Formatting and Annotation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!