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 Center および File ExchangeColormaps についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by