MCPcopy Create free account
hub / github.com/NatLabRockies/windtools / addLabels

Function addLabels

windtools/plotting.py:1286–1329  ·  view source on GitHub ↗

Adds label to subfigures. Inputs ------ axs: axis object Axis to apply the label on. Can be of any shape and dimension loc: str Location of the labels fontsize: scalar Font size alpha: scalar Alpha value pad: int Distance from

(axs,loc='upper right', fontsize=14, alpha=0.6, pad=6, start='a', **bbox_props)

Source from the content-addressed store, hash-verified

1284# ---------------------------------------------
1285
1286def addLabels(axs,loc='upper right', fontsize=14, alpha=0.6, pad=6, start='a', **bbox_props):
1287 '''
1288 Adds label to subfigures.
1289
1290 Inputs
1291 ------
1292 axs: axis object
1293 Axis to apply the label on. Can be of any shape and dimension
1294 loc: str
1295 Location of the labels
1296 fontsize: scalar
1297 Font size
1298 alpha: scalar
1299 Alpha value
1300 pad: int
1301 Distance from corner for label. pad=0 is label touching the corner of the plot
1302 start: char
1303 Character in which to start labeling the subplots
1304 '''
1305
1306 # Ensure axs is iterable
1307 axs = np.array(axs)
1308
1309 if loc == 'upper right': xy=(1,1); xytext=(-pad,-pad); xloc, yloc = 0.97, 0.97; ha='right'; va='top'
1310 elif loc == 'upper left' : xy=(0,1); xytext=( pad,-pad); xloc, yloc = 0.03, 0.97; ha='left'; va='top'
1311 elif loc == 'lower right': xy=(1,0); xytext=(-pad, pad); xloc, yloc = 0.97, 0.03; ha='right'; va='bottom'
1312 elif loc == 'lower left' : xy=(0,0); xytext=( pad, pad); xloc, yloc = 0.03, 0.03; ha='left'; va='bottom'
1313 else:
1314 raise ValueError('loc not recognized. Stopping.')
1315
1316 labels = list(map(chr, range(ord(start), 123)))
1317 if len(axs.flatten()) > len(labels):
1318 # More than a--z, so create 1a, 1b, 1c, 2a, etc. First find the number of numbers number of letters
1319 nN = np.shape(axs)[0]
1320 nL = np.shape(axs)[1]
1321 labels = [str(number) + chr(ord('a') + iletter) for number in range(1, nN + 1) for iletter in range(nL)]
1322
1323 props = dict(facecolor='white', alpha=alpha, edgecolor='silver', boxstyle='square', pad=0.15)
1324 for key,val in bbox_props.items():
1325 props[key] = val
1326
1327 for i, ax in enumerate(axs.flatten()):
1328 ax.annotate(f'$({labels[i]})$', xy=xy, color='black', ha=ha, va=va, xycoords='axes fraction',
1329 xytext=xytext, textcoords='offset points', fontsize=fontsize, bbox=props)
1330
1331
1332class InputError(Exception):

Callers 4

plot_timeheightFunction · 0.85
plot_profileFunction · 0.85
plot_spectrumFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected