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

조회 수: 4 (최근 30일)
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!

채택된 답변

Manish
Manish 2024년 10월 9일
편집: Manish 2024년 10월 9일
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!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by