Scatter plot with timescale colormap

14 次查看(过去 30 天)
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

请先登录,再进行评论。

更多回答(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