Scatter plot with colormap and colorbar based on one of the parameters plotted

4 visualizzazioni (ultimi 30 giorni)
Hello everyone,
I want to plot three parameters using colored scatter plot where the colormap/colorbar represents the values of one of them. Attached file is the example of the datasets containing data_x, data_y, data_z. My intention is using the data_z as the colormap as well as colorbar of the scatterplot.
Thank you!

Risposta accettata

Manish
Manish il 9 Ott 2024
Modificato: Manish il 9 Ott 2024
Hi,
I understand that you want to plot a colored scatterplot with 'data_z' represented on the color map, and 'data_x' and 'data_y' on the other axes.
Here is the code implementation:
% Load the data from the .mat file
data = load('data_xyz.mat');
% Extract the variables
data_x = data.data_x;
data_y = data.data_y;
data_z = data.data_z;
% Create the scatter plot
figure;
scatter(data_x, data_y, 5, data_z, 'filled');
colorbar;
xlabel('Data X');
ylabel('Data Y');
title('Colored Scatter Plot with Z as Colormap');
colormap(jet)%optional
The above figure is the output of the code.
Here is the documentation link for Scatter plot:
Hope this solves!

Più risposte (0)

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by