Scatter plot with timescale colormap

조회 수: 10 (최근 30일)
Adi Purwandana
Adi Purwandana 2024년 10월 11일
편집: Rahul 2024년 10월 14일
Hello everyone,
I have a datasets containing vx, vy, and t date time evolution in excel date format dd/mm/yyyy hh:mm format (see attached dataset). Anyone knows to present this datasets into scatter plot of vx, vy with colormap evolution of time?
My intention is getting scatter plot of vx vs vy with colormap more or less like this:
Thank you!

채택된 답변

Rahul
Rahul 2024년 10월 11일
편집: Rahul 2024년 10월 14일
In order to import an excel spreadsheet and create a scatter plot of timeseries data, involving two variables along with a heatmap based on values of another array.
You can import ‘xlsx’ data using ‘readtable’ function and later convert the ‘datetime’ values stored in ‘t’ column to double data type using ‘datenum’ function, using the following steps:
data = readtable('data_UVT.xlsx');
x = data.vx
y = data.vy
t = datenum(data.t)
Further, a scatter plots can be created using filled face color style, which can be later customized using color profiles by ‘colormap’ function to create a heatmap:
% Create scatter plot
scatter(x, y, 10, t, 'filled'); % 100 is the size of the dots, 'filled' for solid dots
% Add color bar to show the time step mapping
colorbar;
% Add labels
xlabel('X Data Samples (vx)');
ylabel('Y Data Samples (vy)');
title('Scatter Plot with Time-based Color Change');
% Use a colormap (e.g., 'jet', 'parula', etc.)
colormap('jet'); % You can change to 'parula', 'hot', etc.
% Optionally, adjust axis limits if needed
axis tight;
% Customize the color bar to show datetime instead of numeric values
num_ticks = 4; % Number of ticks you want on the colorbar
tick_values = linspace(min(t_numeric), max(t_numeric), num_ticks); % Get the tick positions in numeric form
% Convert the tick positions back to datetime
tick_labels = datestr(tick_values, 'yyyy-mm-dd HH:MM:SS'); % Customize the datetime format as needed
% Apply the tick labels to the colorbar
c.Ticks = tick_values; % Set the tick positions on the colorbar
c.TickLabels = tick_labels; % Set the tick labels as datetime
For more information regarding the functions mentioned above, refer to the following documentation links:
  댓글 수: 3
Rahul
Rahul 2024년 10월 11일
Hey @Adi Purwandana, you can set x-ticks labels and format back to datenum, after the applying the heatmap, using your specified 'datetime' fomat using the properties of the colorbar. Here's how:
data = readtable('data_UVT.xlsx')
x = data.vx;
y = data.vy;
t = data.t;
% Convert datetime to serial date number for plotting
t_numeric = datenum(t);
% Create scatter plot with the numeric time as the color
scatter(x, y, 10, t_numeric, 'filled');
c = colorbar;
xlabel('X Data Samples');
ylabel('Y Data Samples');
title('Scatter Plot with Time-based Color Change');
colormap('jet');
axis tight;
% Customize the color bar to show datetime instead of numeric values
num_ticks = 4; % Number of ticks you want on the colorbar
tick_values = linspace(min(t_numeric), max(t_numeric), num_ticks); % Get the tick positions in numeric form
% Convert the tick positions back to datetime
tick_labels = datestr(tick_values, 'yyyy-mm-dd HH:MM:SS'); % Customize the datetime format as needed
% Apply the tick labels to the colorbar
c.Ticks = tick_values; % Set the tick positions on the colorbar
c.TickLabels = tick_labels; % Set the tick labels as datetime values
Adi Purwandana
Adi Purwandana 2024년 10월 11일
Exactly what I want! Thank you @Rahul

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by