[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} \input{plotting}
\subsection{Scatter plot}
\subsection{Histograms}
\subsection{Heatmaps} \subsection{Heatmaps}
\subsection{3-D plot} \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. 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 A very common scenario is to combine several plots in the same
figure. To do this we create so-called subplots figure. To do this we create so-called subplots
figures\,\ref{regularsubplotsfig},\,\ref{irregularsubplotsfig}. The figures\,\ref{regularsubplotsfig},\,\ref{irregularsubplotsfig}. The

View File

@ -44,8 +44,9 @@ def gradient(p, t, y, scale=None):
def gradient_descent(t, y): def gradient_descent(t, y):
count = 80 count = 80
b_0 = np.mean(y) b_0 = np.mean(y)
omega_0 = 650 omega_0 = 870
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] 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 = np.ones(len(params))
scale[1] = 1000 scale[1] = 1000
eps = 0.01 eps = 0.01

View File

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