Creating proper colour graph

1 次查看(过去 30 天)
Kartavya
Kartavya 2014-11-6
回答: ag 2024-9-25
Hi, I have the following data: set of X coordinates, Y coordinates and the percentage value that each set of coordinate represents. What I want to do is plot each percentage with different colour based on its value (high percentage red, low percentage blue). I'm unfamilar with mesh and many graphical options on matlab.
Thank you,

回答(1 个)

ag
ag 2024-9-25
Hi Kartavya,
To visualize data with color coding based on percentage values, you can use a scatter plot where the color of each point represents its percentage value. MATLAB's scatter function allows you to specify the color of each point using a colormap.
The below code snippet demonstrates how to achieve that, using dummy data:
numPoints = 100;
X = rand(numPoints, 1) * 100;
Y = rand(numPoints, 1) * 100;
percentages = rand(numPoints, 1) * 100;
figure;
scatter(X, Y, 100, percentages, 'filled');
% Set the colormap to 'jet' for a range from blue (low) to red (high)
colormap(jet);
% Add a colorbar to show the mapping of colors to percentage values
colorbar;
xlabel('X Coordinate');
ylabel('Y Coordinate');
title('Scatter Plot with Color-Coded Percentages');
xlim([0, 100]);
ylim([0, 100]);
grid on;
For more details, please refer to the following MathWorks documentations
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by