Multiple plots within 1 figure
I want to make multiple plots within 1 figure
I want to make a plot with days (x axis) and time (y axis set to 30 mins) .
Within each day, I want to make a line (corresponding to when trial was made; new_endpoint) and colour (timepertrial_backtrace).
I want to do this for all the days in that plot but I am not sure how to proceed.
I have put the snippet of code for doing it but it runs for 1 day only.
Any insight will be useful
%%
figure % make new figure
tiledlayout(numel(num_days), 1, ‘TileSpacing’, ‘compact’, ‘Padding’, ‘compact’);
range_col = 800; % range upper limit for my values
for day = 1:numel(num_days)
% Load the variable for the specific day here
load( fullfile(matlist(days_F3187(1,day)).folder, matlist(days_F3187(1,day)).name) ); % Load variables from the .mat file
% the above are .mat file where i store information for each day and I
% load them 1 by 1 as needed
nexttile;
new_endpoint = endpoint / 12000; % 200 Hz frame rate
trial_color_range = parula(range_col+1); % Generating a color range from 0 to range
for i = 1:trialno
% Map the color based on timepertrial_backtrace within the color range
color_index = min(max(round(timepertrial_backtraced(i)), 0), range_col);
trial_color = trial_color_range(color_index + 1, :); % Select color from the color range
% Plotting the line for the current trial with the assigned color
plot([day-1, day], [new_endpoint(i), new_endpoint(i)], ‘Color’, trial_color, ‘LineWidth’, 1);
hold on;
end
hold off;
title([‘Day ‘ num2str(day)]);
xlabel(‘Day’);
ylabel(’30 mins’);
clear trial_color % Clear the trial_color variable for the next iteration
end
sgtitle(‘Timepoints within 30-minute sessions colored based on timepertrial_backtraced’);
This is the figure generated:
However, only 1 day is created and I want information for all the days to be displayed.
How should I approach this problem?I want to make multiple plots within 1 figure
I want to make a plot with days (x axis) and time (y axis set to 30 mins) .
Within each day, I want to make a line (corresponding to when trial was made; new_endpoint) and colour (timepertrial_backtrace).
I want to do this for all the days in that plot but I am not sure how to proceed.
I have put the snippet of code for doing it but it runs for 1 day only.
Any insight will be useful
%%
figure % make new figure
tiledlayout(numel(num_days), 1, ‘TileSpacing’, ‘compact’, ‘Padding’, ‘compact’);
range_col = 800; % range upper limit for my values
for day = 1:numel(num_days)
% Load the variable for the specific day here
load( fullfile(matlist(days_F3187(1,day)).folder, matlist(days_F3187(1,day)).name) ); % Load variables from the .mat file
% the above are .mat file where i store information for each day and I
% load them 1 by 1 as needed
nexttile;
new_endpoint = endpoint / 12000; % 200 Hz frame rate
trial_color_range = parula(range_col+1); % Generating a color range from 0 to range
for i = 1:trialno
% Map the color based on timepertrial_backtrace within the color range
color_index = min(max(round(timepertrial_backtraced(i)), 0), range_col);
trial_color = trial_color_range(color_index + 1, :); % Select color from the color range
% Plotting the line for the current trial with the assigned color
plot([day-1, day], [new_endpoint(i), new_endpoint(i)], ‘Color’, trial_color, ‘LineWidth’, 1);
hold on;
end
hold off;
title([‘Day ‘ num2str(day)]);
xlabel(‘Day’);
ylabel(’30 mins’);
clear trial_color % Clear the trial_color variable for the next iteration
end
sgtitle(‘Timepoints within 30-minute sessions colored based on timepertrial_backtraced’);
This is the figure generated:
However, only 1 day is created and I want information for all the days to be displayed.
How should I approach this problem? I want to make multiple plots within 1 figure
I want to make a plot with days (x axis) and time (y axis set to 30 mins) .
Within each day, I want to make a line (corresponding to when trial was made; new_endpoint) and colour (timepertrial_backtrace).
I want to do this for all the days in that plot but I am not sure how to proceed.
I have put the snippet of code for doing it but it runs for 1 day only.
Any insight will be useful
%%
figure % make new figure
tiledlayout(numel(num_days), 1, ‘TileSpacing’, ‘compact’, ‘Padding’, ‘compact’);
range_col = 800; % range upper limit for my values
for day = 1:numel(num_days)
% Load the variable for the specific day here
load( fullfile(matlist(days_F3187(1,day)).folder, matlist(days_F3187(1,day)).name) ); % Load variables from the .mat file
% the above are .mat file where i store information for each day and I
% load them 1 by 1 as needed
nexttile;
new_endpoint = endpoint / 12000; % 200 Hz frame rate
trial_color_range = parula(range_col+1); % Generating a color range from 0 to range
for i = 1:trialno
% Map the color based on timepertrial_backtrace within the color range
color_index = min(max(round(timepertrial_backtraced(i)), 0), range_col);
trial_color = trial_color_range(color_index + 1, :); % Select color from the color range
% Plotting the line for the current trial with the assigned color
plot([day-1, day], [new_endpoint(i), new_endpoint(i)], ‘Color’, trial_color, ‘LineWidth’, 1);
hold on;
end
hold off;
title([‘Day ‘ num2str(day)]);
xlabel(‘Day’);
ylabel(’30 mins’);
clear trial_color % Clear the trial_color variable for the next iteration
end
sgtitle(‘Timepoints within 30-minute sessions colored based on timepertrial_backtraced’);
This is the figure generated:
However, only 1 day is created and I want information for all the days to be displayed.
How should I approach this problem? plot, tiledplot, multiple figure, subplot MATLAB Answers — New Questions