Scatter plot with timescale colormap

10 visualizzazioni (ultimi 30 giorni)
Adi Purwandana
Adi Purwandana il 11 Ott 2024
Modificato: Rahul il 14 Ott 2024
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!

Risposta accettata

Rahul
Rahul il 11 Ott 2024
Modificato: Rahul il 14 Ott 2024
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 Commenti
Rahul
Rahul il 11 Ott 2024
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 il 11 Ott 2024
Exactly what I want! Thank you @Rahul

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by