[plotting] scatterplot

This commit is contained in:
Jan Grewe 2018-02-26 11:45:06 +01:00
parent 7884e1842b
commit c84fb6b944
6 changed files with 118 additions and 42 deletions

View File

@ -0,0 +1,28 @@
x = 1:2:100;
y = (0.5 .* x - 0.56) + randn(size(x)) .* 5.;
f = figure();
set(f, 'paperunits', 'centimeter', 'papersize', [15, 5], ...
'paperposition', [0, 0, 15, 5], 'color', 'white');
subplot(1, 3, 1);
scatter(x, y, 15, 'r', 'filled');
xlabel('x');
ylabel('y');
text(-35, max(ylim) * 1.075,'A', 'FontSize', 12);
subplot(1, 3, 2)
scatter(x, y, 1:length(x), 'r');
xlabel('x');
ylabel('y');
text(-35, max(ylim) * 1.075,'B', 'FontSize', 12);
subplot(1, 3, 3)
colors = zeros(length(x),3);
colors(:,1) = round(1:255/length(x):255)/255';
scatter(x, y, 15, colors, 'filled')
xlabel('x');
ylabel('y');
text(-35, max(ylim) * 1.075,'C', 'FontSize', 12);
saveas(f, '../lecture/images/scatterplot.png')

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -16,10 +16,6 @@
\input{plotting}
\subsection{Scatter plot}
\subsection{Histograms}
\subsection{Heatmaps}
\subsection{3-D plot}

View File

@ -444,7 +444,51 @@ various examples and the respective code on their website
For some types of plots we present examples in the following sections.
\subsection{Line plot, subplots}
\subsection{Scatter}
For displaying events or pairs of x-y coordinates the standard line
plot is not optimal. Rather, we use \code[scatter()]{scatter} for this
purpose. For example, we have a number of measurements of a system's
response to a certain stimulus intensity. There is no dependency
between the data points, drawing them with a line-plot would be
nonsensical (figure\,\ref{scatterplotfig}\,A). In contrast to
\codeterm{}{plot} we need to provide x- and y-coordinates in order to
draw the data. In the example we also provide further arguments to set
the size, color of the dots and specify that they are filled
(listing\,\ref{scatterlisting1}).
\lstinputlisting[caption={Creating a scatter plot with red filled dots.},
label=scatterlisting1, firstline=9, lastline=9]{scatterplot.m}
We could have used plot for this purpose and set the marker to
something and the line-style to ``none'' to draw an equivalent
plot. Scatter, however offers some more advanced features that allows
to add two more dimensions to the plot
(figure\,\ref{scatterplotfig}\,B,\,C). For each dot one can define an
individual size and color. In this example the size argument is simply
a vector of the same size as the data that contains number from 1 to
the length of 'x' (line 1 in listing\,\ref{scatterlisting2}). To
manipulate the color we need to specify a length(x)-by-3 matrix. For
each dot we provide an individual color (i.e. the RGB triplet in each
row of the color matrix, lines 2-4 in listing\,\ref{scatterlisting2})
\lstinputlisting[caption={Creating a scatter plot with size and color
variations. The RGB triplets define the respective color intensity
in a range 0:1. Here, we modify only the red color channel.},
label=scatterlisting2, linerange={15-15, 21-23}]{scatterplot.m}
\begin{figure}[t]
\includegraphics{scatterplot}
\titlecaption{Scatterplots.}{Scatterplots are used to draw
datapoints where there is no direct dependency between the
individual measurements (like time). Scatter offers several
advantages over the standard plot command. One can vary the size
and/or the color of each dot.}\label{scatterplotfig}
\end{figure}
\subsection{Subplots}
A very common scenario is to combine several plots in the same
figure. To do this we create so-called subplots
figures\,\ref{regularsubplotsfig},\,\ref{irregularsubplotsfig}. The

View File

@ -44,8 +44,9 @@ def gradient(p, t, y, scale=None):
def gradient_descent(t, y):
count = 80
b_0 = np.mean(y)
omega_0 = 650
params = [b_0, omega_0, np.min(y) + np.max(y), np.pi/2, (np.min(y) + np.max(y))/2, np.pi/3, (np.min(y) + np.max(y))/4, np.pi/4, (np.min(y) + np.max(y))/5, np.pi]
omega_0 = 870
amplitude = np.max(y) - np.min(y)
params = [b_0, omega_0, amplitude, np.pi/2, amplitude/2, np.pi/3, amplitude/4, np.pi/4, amplitude/5, np.pi]
scale = np.ones(len(params))
scale[1] = 1000
eps = 0.01

View File

@ -13,8 +13,8 @@
%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry}
\pagestyle{headandfoot} \header{{\bfseries\large \"Ubung
}}{{\bfseries\large Korrelation Stimulus und Antwort}}{{\bfseries\large 20. Dezember, 2016}}
\pagestyle{headandfoot} \header{{\bfseries\large Exercise
}}{{\bfseries\large Correlation of stimulus and response}}{{\bfseries\large December 19, 2017}}
\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email:
jan.grewe@uni-tuebingen.de} \runningfooter{}{\thepage}{}
@ -24,54 +24,61 @@
\renewcommand{\baselinestretch}{1.15}
\newcommand{\code}[1]{\texttt{#1}}
\renewcommand{\solutiontitle}{\noindent\textbf{L\"osung:}\par\noindent}
\renewcommand{\solutiontitle}{\noindent\textbf{Solution:}\par\noindent}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\vspace*{-6.5ex}
\begin{center}
\textbf{\Large Einf\"uhrung in die wissenschaftliche Datenverarbeitung}\\[1ex]
\textbf{\Large Introduction to scientific computing}\\[1ex]
{\large Jan Grewe, Jan Benda}\\[-3ex]
Abteilung Neuroethologie \hfill --- \hfill Institut f\"ur Neurobiologie \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\
\end{center}
\begin{questions}
\question Stellt die zeitabh\"angige Feuerrate eines Neurons
dar. Diese soll mit der Faltungsmethode bestimmt werden. Verwendet
den Datensatz \code{lifoustim.mat}. Dieser enth\"at drei Variablen:
1. die Spikezeiten, 2. den Stimulus und 3. die zeitliche
Aufl\"osung. Die Dauer eines Trials betr\"agt 30 Sekunden.
\question Estimate the time-dependent firing rate of a neuron. Use
the ``convoluion'' method to do it. The dataset \code{lifoustim.mat}
contains three variables. 1st the spike times in different trials,
2nd the stimulus, and 3rd the temporal resolution. The total
duration of each trial amounts to 30 seconds.
\begin{parts}
\part Schreibt eine Funktion, die einen Vektor mit Spikezeiten,
die Dauer des Trials, und die zeitliche Aufl\"osung entgegennimmt
und die Zeitachse sowie die Feuerrate zur\"uckgibt.
\part Benutzt diese Funktion in einem Skript und stellt die Feuerrate
eines einzelnen Trials sowie den Mittelwert \"uber alle Trials
dar.
\part Erweitert das Programm so, dass die Abbildung den Richtlinien
des \textit{Journal of Neuroscience} entspricht
(Schriftgr\"o{\ss}e, Abbildungsgr\"o{\ss}e).
\part Die Abbildung sollte als pdf gespeichert werden.
\part{} Write a function that estimates the firing rate with the
``convolution'' method. This function should take four input
arguments: (i) a vector of spike times, (ii) the temporal
resolution of the recording, (iii) the duration of the
trial, and (iv) the standard deviation of the applied Gaussian
kernel. The function should return two variables: (i) the firing
rate, and (ii) a vector representing time.
\part{} Write a script that uses this function to estimate the
firing rate of all trial. Plot the mean (across trials) firing
rate as a function of time. Use two different kernel standard
deviations (e.g. 20\,ms and 100\,ms).
\part{} Save the figure according the style defined by the
\emph{J. Neuroscience} (figure width 1, 1.5, or two columns, 8.5,
11.6, or 17.6\,cm, respectively; fontsize 10 pt). Save the figure
as pdf.
\end{parts}
\question In einer vorherigen \"Ubung wurde die Korrelation zwischen
einer Reihe von Messungen und einer entsprechenden Anzahl
unabh\"angiger Variablen bestimmt (Kapitel 4.4 im Skript). Wir
k\"onnen diese Korrelation benutzen um den Zusammenhang zwischen
Stimulus und Antwort zu bestimmen.
\question In a previous exercise you were asked to estimate the
correlation between a set of independent variables and the
respective measurements (Chapter 6.4 in the script). We can use
this function to learn a few things about the relation between
stimulus and response.
\begin{parts}
\part Ermittelt die zeitabh\"angige Feuerrate mit einer der drei
Methoden und korrelliert sie mit dem Stimulus.
\part Verschiebt nun den Stimulus relativ zur Antwort um $\pm$
50\,ms in 1\,ms Schritten und berechnet f\"ur jede Verschiebung
die Korrelation.
\part Stellt die so berechnete Kreuzkorrelation graphisch dar
(x-Achse die Verschiebung, y-Achse der Korrelationskoeffizient).
\part Was ist die maximale Korrelation und bei welcher
Verschiebung kommt sie vor?
\part Was k\"onnte uns die Breite des Korrelationspeaks sagen?
\part{} Estimate the firing rate of the neuronal response using one
of the three methods. Use the same dataset as before.
\part{} Calculate the correlation of stimulus and response.
\part{} Calculate the correlation of stimulus and response
while shifting the response relative to the stimulus in a range
$\pm$ 50\,ms (1\,ms steps).
\part{} Plot these correlations as a function of the temporal shift
(often called lag).
\part{} What is the maximum correlation and at which lag does it occur?
\part{} What could this tell us about the neuronal response properties?
\end{parts}
\end{questions}
\end{document}
\end{document}