Skip to content

Commit 9d14e66

Browse files
authored
Merge pull request #52 from Julie-Fabre/bleeding_edge
update prettify_matlab subtree
2 parents 7bd0eb4 + ed4106e commit 9d14e66

File tree

14 files changed

+1108
-665
lines changed

14 files changed

+1108
-665
lines changed

prettify-matlab/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ Uses the matrices from:
4343
#### To do list
4444
- [ ] Perceptually-uniform, colorblind friendly colormaps.
4545
- [ ] Prettify colorbars and labels
46-
- [ ] Add pvalue bars above plots
4746
- [ ] wrap titles/labels
48-
- [ ] bar plots, violin plots
4947
- [ ] shaded, shaded gradual
5048

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
% generate an uglyPlot
3+
uglyPlot;
4+
5+
% Make it pretty with default settings
6+
prettify_plot;
7+
8+
% Change the figure color, fonts, fontsizes, ticks
9+
prettify_plot('FigureColor', 'k')
10+
prettify_plot('FigureColor', 'none', 'Font', 'Times','TitleFontSize', 12, 'LabelFontSize', 14,'GeneralFontSize', 12,...
11+
'AxisTicks', 'in', 'TickLength', 0.01, 'TickWidth', 1)
12+
13+
% let's go back to the defaults
14+
prettify_plot;
15+
16+
% Homogenize the x, y and climits by rows of subplots (other options include by columns
17+
% ('col') and for all aubplots ('all')
18+
prettify_plot('YLimits', 'cols', 'XLimits', 'all')
19+
20+
% Change colormaps, make symmetric
21+
prettify_plot('CLimits', 'all', 'SymmetricalCLimits', true, 'ChangeColormaps', true)
22+
23+
% Change the legends
24+
prettify_plot('LegendReplace', true)
25+
26+
% Replace axis by scale bars
27+
prettify_addScaleBars
28+
29+
% Add p-values
Lines changed: 98 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,98 @@
1-
%% uglyPlot
2-
3-
% Define x values
4-
x = linspace(0, 2*pi, 1000);
5-
6-
% Define y values for various functions
7-
y1 = sin(x);
8-
y2 = cos(x);
9-
y3 = tan(x);
10-
y4 = log(x + 1); % Adding 1 to avoid negative values and log(0)
11-
y_cot = cot(x); % Cotangent values
12-
13-
% Create a new figure
14-
figure(2); clf;
15-
16-
17-
%% line plots
18-
% First subplot: sine curve
19-
subplot(2, 3, 1);
20-
plot(x, y1, 'r');
21-
hold on; % Keep the current plot and add new plots to it
22-
plot(x, 0.5*ones(size(x)), 'k--'); % Dashed line at y = 0.5
23-
title('Sine Curve');
24-
xlabel('x');
25-
ylabel('sin(x)');
26-
legend('sin(x)', 'y = 0.5');
27-
28-
% Second subplot: cosine curve
29-
subplot(2, 3, 4);
30-
plot(x, y2, 'b');
31-
hold on;
32-
% Sample points
33-
x_points = [pi/4, pi/2, 3*pi/4];
34-
y_points = cos(x_points);
35-
plot(x_points, y_points, 'ro'); % red circles
36-
title('Cosine Curve');
37-
xlabel('x');
38-
ylabel('cos(x)');
39-
40-
% scatter plots
41-
42-
numDots = 20;
43-
subplot(2, 3, 2);
44-
x = rand(numDots, 1); % Random numbers between 0 and 1 for the x-axis
45-
y = rand(numDots, 1); % Random numbers between 0 and 1 for the y-axis
46-
scatter(x, y);
47-
xlabel('X-axis');
48-
ylabel('Y-axis');
49-
title('Scatter Plot of Random Dots');
50-
51-
52-
53-
numDots = 25;
54-
subplot(2, 3, 5);
55-
x = rand(numDots, 1); % Random numbers between 0 and 1 for the x-axis
56-
y = rand(numDots, 1); % Random numbers between 0 and 1 for the y-axis
57-
scatter(x, y);
58-
xlabel('X-axis');
59-
ylabel('Y-axis');
60-
title('Scatter Plot of Random Dots');
61-
62-
%% images
63-
time = linspace(0, 24, 100); % Time from 0 to 24 hours
64-
activity = cumsum(randn(15, 100)); % Random walk for activity
65-
subplot(2, 3, 3);
66-
uglyColors = [1 0 1; 0 1 0; 0 0 1; 1 1 0; 1 0.5 0.2];
67-
colormap(uglyColors);
68-
imagesc(time, [], activity);
69-
ylabel('Activity');
70-
xlabel('Time (ms)');
71-
c = colorbar;
72-
c.Title.String = 'Zscore';
73-
74-
% Activity plot
75-
time = linspace(0, 24, 100); % Time from 0 to 24 hours
76-
activity = cumsum(randn(15, 100)).*2; % Random walk for activity
77-
subplot(2, 3, 6);
78-
uglyColors = [1 0 1; 0 1 0; 0 0 1; 1 1 0; 1 0.5 0.2];
79-
colormap(uglyColors);
80-
% Plot the activity data
81-
imagesc(time, [], activity);
82-
ylabel('Activity');
83-
xlabel('Time (ms)');
84-
c2 = colorbar;
85-
c2.Title.String = 'Zscore';
86-
87-
prettify_plot;
1+
% Create a 3x4 subplot
2+
figure;
3+
4+
% Parameters for simulation
5+
time = linspace(0, 2, 2000); % Time vector
6+
stimulus_onset = 0.5; % Time of stimulus onset
7+
stimulus_duration = 0.2; % Duration of the stimulus
8+
response_delay = 0.3; % Response delay after stimulus onset
9+
response_duration = 0.25; % Duration of the response
10+
noise_amplitude = 0.5; % Amplitude of noise
11+
12+
% Simulate stimulus
13+
stimulus = zeros(size(time));
14+
stimulus((time >= stimulus_onset) & (time < stimulus_onset + stimulus_duration)) = 1;
15+
16+
% Simulate neurons
17+
neuron1_response = 12 * exp(-(time - (stimulus_onset + response_delay)) / response_duration) .* (time >= (stimulus_onset + response_delay)) +...
18+
noise_amplitude * randn(size(time));
19+
neuron2_response = 0.5 * exp(-(time - (stimulus_onset + response_delay)) / response_duration) .* (time >= (stimulus_onset + response_delay)) +...
20+
+ noise_amplitude * randn(size(time));
21+
neuron3_response = 22 * -exp(-(time - (stimulus_onset + response_delay)) / response_duration) .* (time >= (stimulus_onset + response_delay))+...
22+
noise_amplitude * randn(size(time));
23+
24+
% Plot the simulated responses
25+
subplot(3, 3, 1);
26+
plot(time, neuron1_response);
27+
xlim([0 1])
28+
xlabel('Time');
29+
ylabel('Response');
30+
31+
subplot(3, 3, 4);
32+
plot(time, neuron2_response);
33+
xlabel('Time');
34+
ylabel('Response');
35+
36+
subplot(3, 3, 7);
37+
plot(time, neuron3_response);
38+
xlabel('Time');
39+
ylabel('Response');
40+
41+
% simulate PSTH
42+
% Define a function to generate neuron responses
43+
generate_neuron_response = @(amplitude) amplitude * exp(-(time - (stimulus_onset + response_delay)) / response_duration) .* ...
44+
(time >= (stimulus_onset + response_delay)) + amplitude * randn(size(time));
45+
46+
noise_amplitude = 0.1;
47+
% Use arrayfun to generate responses for all neurons
48+
neurons1_amplitudes = [-2:0.5:12];
49+
neurons_1 = arrayfun(generate_neuron_response, neurons1_amplitudes, 'UniformOutput', false);
50+
neurons_1_matrix = cell2mat(neurons_1');
51+
52+
neurons2_amplitudes = [-0.5:0.01:0.5];
53+
neurons_2 = arrayfun(generate_neuron_response, neurons2_amplitudes, 'UniformOutput', false);
54+
neurons_2_matrix = cell2mat(neurons_2');
55+
56+
neurons3_amplitudes = [-22:1:1];
57+
neurons_3 = arrayfun(generate_neuron_response, neurons3_amplitudes, 'UniformOutput', false);
58+
neurons_3_matrix = cell2mat(neurons_3');
59+
60+
61+
% plot PSTHs
62+
subplot(3, 3, 2);
63+
imagesc(time, [], neurons_1_matrix)
64+
colormap("jet")
65+
cb = colorbar;
66+
cb.Title.String = 'Activity';
67+
68+
subplot(3, 3, 5);
69+
imagesc(time, [], neurons_2_matrix)
70+
colormap("jet")
71+
colorbar;
72+
73+
subplot(3, 3, 8);
74+
imagesc(time, [], neurons_3_matrix)
75+
colormap("jet")
76+
colorbar;
77+
78+
% plot some lines
79+
average_psth1 = smoothdata(mean(neurons_1_matrix, 1),'gaussian', [0, 100]);
80+
average_psth2 = smoothdata(mean(neurons_2_matrix, 1), 'gaussian',[0, 100]);
81+
average_psth3 = smoothdata(mean(neurons_3_matrix, 1), 'gaussian',[0, 100]);
82+
83+
84+
subplot(3, 3, [3,6,9]); hold on;
85+
plot(time, average_psth2);
86+
plot(time, average_psth3);
87+
plot(time, average_psth1);
88+
89+
90+
legend('Type 1', 'Type 2', 'Type 3')
91+
92+
93+
94+
95+
96+
97+
% Adjust the layout of the subplots
98+
sgtitle('Demo');

0 commit comments

Comments
 (0)