Creating proper colour graph

1 visualización (últimos 30 días)
Kartavya
Kartavya el 6 de Nov. de 2014
Respondida: ag el 25 de Sept. de 2024
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,

Respuestas (1)

ag
ag el 25 de Sept. de 2024
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!

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by