Plotting tools
utilz.plot
Plotting convenience functions
mpinit(figsize=(8, 6), subplots=(1, 1))
Setup matplotlib subplots boilerplate
Parameters:
Name | Type | Description | Default |
---|---|---|---|
figsize |
tuple
|
Figure size. Defaults to (8, 6). |
(8, 6)
|
subplots |
tuple
|
subplot grid size. Defaults to (1, 1). |
(1, 1)
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
Figure, Axes
|
matplotlib figure handle and axes |
Source code in utilz/plot.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
newax(*args, **kwargs)
Short hand for a new axis on a new figure. Usueful for calling multiple plotting routines in a pipe() but wanting separate figures.
Source code in utilz/plot.py
266 267 268 269 |
|
savefig(f, name, path=None, raster=True, vector=True, use_subdirs=True, raster_extension='jpg', bbox_inches='tight', overwrite=True, **kwargs)
Quick figure saving function. Saves raster (jpg) and vector (pdf) by default. Can also optionally prevent file-overwriting
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
Figure
|
matplotlib figure handle |
required |
path |
Path
|
directory to save figure as a Path object. Defaults to |
None
|
name |
str
|
filename without extension |
required |
raster |
bool
|
whether to save raster file. Defaults to True. |
True
|
vector |
bool
|
whether to save vector file. Defaults to True. |
True
|
use_subdirs |
bool
|
whether to split saving of raster and vector files |
True
|
raster_extension |
str
|
raster file type. Defaults to "jpg". |
'jpg'
|
bbox_inches |
str
|
see bbox_inches in plt.savefig. Defaults to "tight". |
'tight'
|
overwrite |
bool
|
whether to overwrite any existing files. Defaults to True. |
True
|
Source code in utilz/plot.py
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 |
|
setcontext(data, context='notebook', font_scale=1, rc=None)
Modify a plot context. Just call it once in a pipe at some point prior to any plot commands or functions. Call it with default args to reset. Intended to be used inside a pipe, because pipe's always reset context before they run
Source code in utilz/plot.py
256 257 258 259 260 261 262 263 |
|
stripbarplot(data, pointcolor='black', remove_duplicate_legend=True, xlabel=None, ylabel=None, xticklabels=None, yticklabels=None, xticks=None, yticks=None, xlim=None, ylim=None, *args, **kwargs)
Combines a call to sns.barplot
+ sns.stripplot
. Optionally set some axis level attributes during plot creation. Leaving these attributes None will return the default labels that seaborn sets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
input data |
required |
pointcolor |
str
|
color of stripplot points. Defaults to "black". |
'black'
|
xlabel |
[type]
|
x-axis label. Defaults to seaborn's default. |
None
|
ylabel |
[type]
|
Defaults to seaborn's default. |
None
|
xticklabels |
[type]
|
Defaults to seaborn's default. |
None
|
yticklabels |
[type]
|
Defaults to seaborn's default. |
None
|
xticks |
[type]
|
Defaults to seaborn's default. |
None
|
yticks |
[type]
|
Defaults to seaborn's default. |
None
|
xlim |
[type]
|
Defaults to seaborn's default. |
None
|
ylim |
[type]
|
Defaults to seaborn's default. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Axis |
Axes
|
plot axis handle |
Source code in utilz/plot.py
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 |
|
tweak(plot, **kwargs)
swiss-army knife to quickly change most aesthetics on a plot, e.g. tick labels, fontsize, etc, in a unified function call
Source code in utilz/plot.py
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 249 250 251 252 253 |
|