[plotting] scatterplot
This commit is contained in:
28
plotting/code/scatterplot.m
Normal file
28
plotting/code/scatterplot.m
Normal 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')
|
||||
BIN
plotting/lecture/images/scatterplot.png
Normal file
BIN
plotting/lecture/images/scatterplot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
@@ -16,10 +16,6 @@
|
||||
|
||||
\input{plotting}
|
||||
|
||||
\subsection{Scatter plot}
|
||||
|
||||
\subsection{Histograms}
|
||||
|
||||
\subsection{Heatmaps}
|
||||
|
||||
\subsection{3-D plot}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user