Base
colored_line(x, y, c, ax, **lc_kwargs)
Plot a line with a color specified along the line by a third value. Code copied from matplotlib website.
It does this by creating a collection of line segments. Each line segment is made up of two straight lines each connecting the current (x, y) point to the midpoints of the lines connecting the current point with its two neighbors. This creates a smooth line with no gaps between the line segments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
ndarray
|
Horizontal coordinates of data points |
required |
y
|
ndarray
|
Vertical coordinates of data points |
required |
c
|
ndarray
|
The color values, which should be the same size as |
required |
ax
|
Axes
|
Axis object on which to plot the colored line. |
required |
**lc_kwargs
|
Any additional arguments to pass to matplotlib.collections.LineCollection constructor. This should not include the array keyword argument because that is set to the color argument. If provided, it will be overridden. |
{}
|
Returns:
Type | Description |
---|---|
LineCollection
|
The generated line collection representing the colored line. |
Source code in isca_tools/plot/base.py
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 |
|
fig_resize(fig, width_fig_desired=None, ar=4 / 3)
Change height of figure such that aspect ratio of each subplot is set to ar
, while the width is maintained
at the same value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure to resize. |
required |
width_fig_desired
|
Optional[float]
|
Width of figure after resize in inches. If not provided, will keep current width. |
None
|
ar
|
float
|
Desired aspect ratio (width/height) of each subplot within |
4 / 3
|
Source code in isca_tools/plot/base.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
get_fig_n_rows_cols(fig)
Returns the number of rows and columns of subplots in a figure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure to find subplot arrangement for. |
required |
Returns:
Name | Type | Description |
---|---|---|
n_row |
int
|
Number of rows of subplots. |
n_col |
int
|
Number of columns of subplots. |
Source code in isca_tools/plot/base.py
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 |
|
label_subplots(fig, ax_list, labels=None, fontsize=9, fontcolor='k', box_alpha=1, pos_x=5, pos_y=-5)
This adds a label to each subplot in the top right corner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure containing subplots to add labels to. |
required |
ax_list
|
Union[Axes, List[Axes]]
|
[n_ax] List of all axes in the figure. If only one figure, can just provide the axes and not a list. |
required |
labels
|
Optional[List[str]]
|
[n_ax] Label for each subplot. If not given, the label will just be the letters of the alphabet: a, b, c, ... |
None
|
fontsize
|
float
|
Font size to use |
9
|
fontcolor
|
str
|
What color font to use |
'k'
|
box_alpha
|
float
|
Opacity of box bounding text (1 is opaque and 0 is transparent) |
1
|
pos_x
|
float
|
Can specify distance from top right corner. |
5
|
pos_y
|
float
|
Can specify distance from top right corner (should be negative). |
-5
|
Source code in isca_tools/plot/base.py
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 |
|
savefig(fig, file_name='output', output_dir='/Users/joshduffield/Desktop/', format='pdf', dpi=800, bbox_inches='tight', pad_inches=0.05, overwrite_file=False, save_if_exists=True)
Function to save figure, basically just calls
plt.savefig
but has more useful
default values, and option to not overwrite figure if already exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Matplolib figure that you would like to save |
required |
file_name
|
str
|
Name of saved figure file in |
'output'
|
output_dir
|
str
|
Directory into which figure file will be saved. |
'/Users/joshduffield/Desktop/'
|
format
|
str
|
The file format, e.g. |
'pdf'
|
dpi
|
Union[float, str]
|
The resolution in dots per inch. If |
800
|
bbox_inches
|
Optional[str]
|
Bounding box in inches: only the given portion of the figure is saved.
If |
'tight'
|
pad_inches
|
Union[float, str]
|
Amount of padding in inches around the figure when bbox_inches is 'tight'.
If |
0.05
|
overwrite_file
|
bool
|
If |
False
|
save_if_exists
|
bool
|
If |
True
|
Source code in isca_tools/plot/base.py
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 |
|
update_fontsize(fig, base_fontsize=8, base_ax_width=2.464)
Resize fontsize based on subplot width, given that base_fontsize
is a good fontsize for a subplot
of width base_ax_width
inches.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure to change fontsize for. |
required |
base_fontsize
|
float
|
A good fontsize for a subplot of width |
8
|
base_ax_width
|
float
|
A subplot of width |
2.464
|
Source code in isca_tools/plot/base.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
update_linewidth(fig, base_linewidth=1, base_ax_width=2.464)
Resize linewidths based on subplot width, given that base_linewidth
is a good linewidth for a subplot
of width base_ax_width
inches.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
Figure to change linewidth for. |
required |
base_linewidth
|
float
|
A good linewidth for a subplot of width |
1
|
base_ax_width
|
float
|
A subplot of width |
2.464
|
Source code in isca_tools/plot/base.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|