-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02B-Controlling figure aesthetics.tex
More file actions
248 lines (222 loc) · 6.74 KB
/
02B-Controlling figure aesthetics.tex
File metadata and controls
248 lines (222 loc) · 6.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
\documentclass{beamer}
\usepackage{framed}
\usepackage{graphicx}
\begin{document}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{itemize}
\item Some plots benefit from offsetting the spines away from the data, which can also be done when calling \texttt{despine()}.
\item When the ticks don’t cover the whole range of the axis, the trim parameter will limit the range of the surviving spines.
\end{itemize}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{verbatim}
f, ax = plt.subplots()
sns.violinplot(data)
sns.despine(offset=10, trim=True);
\end{verbatim}
\begin{figure}
\centering
\includegraphics[width=0.7\linewidth]{images/aesthetics_23_0}
\end{figure}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
You can also control which spines are removed with additional arguments to \texttt{despine()}:
\begin{verbatim}
sns.set_style("whitegrid")
sns.boxplot(data=data, palette="deep")
sns.despine(left=True)
\end{verbatim}
\begin{figure}
\centering
\includegraphics[width=0.6\linewidth]{images/aesthetics_25_0}
\caption{}
\label{fig:aesthetics_25_0}
\end{figure}
\end{frame}
\section{Temporarily setting figure style}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{itemize}
\item Although it’s easy to switch back and forth, you can also use the \texttt{axes\_style()} function in a with statement to temporarily set plot parameters.
\item This also allows you to make figures with differently-styled axes:
\end{itemize}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{verbatim}
with sns.axes_style("darkgrid"):
plt.subplot(211)
sinplot()
plt.subplot(212)
sinplot(-1)
\end{verbatim}
\begin{figure}
\centering
\includegraphics[width=0.7\linewidth]{images/aesthetics_27_0}
\end{figure}
\end{frame}
\section{Overriding elements of the seaborn styles}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\noindent \textbf{Overriding elements of the seaborn styles}\\
\begin{itemize}
\item If you want to customize the seaborn styles, you can pass a dictionary of parameters to the \texttt{rc} argument of \texttt{axes\_style()} and \texttt{set\_style()}.
\end{itemize}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{itemize}
\item Note that you can only override the parameters that are part of the style definition through this method. (However, the higher-level \texttt{set()} function takes a dictionary of any matplotlib parameters).
\item
If you want to see what parameters are included, you can just call the function with no arguments, which will return the current settings:
\end{itemize}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{verbatim}
sns.axes_style()
{'axes.axisbelow': True,
'axes.edgecolor': '.8',
'axes.facecolor': 'white',
'axes.grid': True,
'axes.labelcolor': '.15',
'axes.linewidth': 1.0,
'figure.facecolor': 'white',
'font.family': [u'sans-serif'],
'font.sans-serif': [u'Arial',
...
...
\end{verbatim}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
You can then set different versions of these parameters:
\begin{verbatim}
sns.set_style("darkgrid", {"axes.facecolor": ".9"})
sinplot()
\end{verbatim}
\begin{figure}
\centering
\includegraphics[width=0.7\linewidth]{images/aesthetics_31_0}
\end{figure}
\end{frame}
\section{Scaling plot elements with plotting\_context() and set\_context()}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{itemize}
\item Scaling plot elements with \texttt{plotting\_context()} and \texttt{set\_context()}
\item A separate set of parameters control the scale of plot elements, which should let you use the same code to make plots that are suited for use in settings where larger or smaller plots are appropriate.
\end{itemize}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
First let’s reset the default parameters by calling \texttt{set()}:
\begin{verbatim}
sns.set()
\end{verbatim}
\begin{itemize}
\item The four preset contexts, in order of relative size, are paper, notebook, talk, and poster.
\item The notebook style is the default, and was used in the plots above.
\end{itemize}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{verbatim}
sns.set_context("paper")
plt.figure(figsize=(8, 6))
sinplot()
\end{verbatim}
\begin{figure}
\centering
\includegraphics[width=0.7\linewidth]{images/aesthetics_35_0}
\end{figure}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{verbatim}
sns.set_context("talk")
plt.figure(figsize=(8, 6))
sinplot()
\end{verbatim}
\begin{figure}
\centering
\includegraphics[width=0.7\linewidth]{images/aesthetics_36_0}
\end{figure}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{verbatim}
sns.set_context("poster")
plt.figure(figsize=(8, 6))
sinplot()
\end{verbatim}
\begin{figure}
\centering
\includegraphics[width=0.7\linewidth]{images/aesthetics_37_0}
\end{figure}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{itemize}
\item Most of what you now know about the style functions should transfer to the context functions.
\item You can call \texttt{set\_context()} with one of these names to set the parameters, and you can override the parameters by providing a dictionary of parameter values.
\end{itemize}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{itemize}
\item You can also independently scale the size of the font elements when changing the context.
\item This option is also available through the top-level \texttt{set()} function.
\end{itemize}
\end{frame}
%====================================%
\begin{frame}[fragile]
\frametitle{Seaborn Workshop}
\large
\begin{verbatim}
sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 2.5})
sinplot()
\end{verbatim}
\begin{figure}
\centering
\includegraphics[width=0.7\linewidth]{images/aesthetics_39_0}
\end{figure}
Similarly (although it might be less useful), you can temporarily control the scale of figures nested under a with statement.
\end{frame}
%====================================%
\end{document}