Skip to content

skais_mapper.plotting

Plotting routines for maps and images.

Functions:

Name Description
plot_image

Plot map from an array, tensor, or batch(es).

plot_image_array

Plot map from an array or batch(es).

plot_image_from_batch

Plot map from an array/tensor batch (optionally including metadata).

plot_image_quantity

Plot map from an astropy.units.Quantity array or batch(es).

plot_image_tensor

Plot map from a tensor, or batch(es).

plot_image

plot_image(
    data: Any,
    batch_idx: int | None = None,
    extent: Sequence[float] | None = None,
    colormap: None = None,
    colorbar: bool = False,
    colorbar_label: str | None = None,
    xlabel: str | None = None,
    ylabel: str | None = None,
    savefig: bool = False,
    path: str | Path | None = None,
    show: bool = False,
    close: bool = False,
    verbose: bool = False,
    **kwargs,
)

Plot map from an array, tensor, or batch(es).

Parameters:

Name Type Description Default
data Any

Array(s) of a map (or maps).

required
batch_idx int | None

If not None, data is a single or multiple batches of images.

None
info

Supplementary information about the data.

required
extent Sequence[float] | None

Extent of the map in physical units.

None
colormap None

Name of the colormap to use for plotting.

None
colorbar bool

If True, include the colorbar in the plot.

False
colorbar_label str | None

Label of the colorbar (if enabled).

None
xlabel str | None

Label of the x-axis.

None
ylabel str | None

Label of the y-axis.

None
savefig bool

If True, save the plot to file.

False
path str | Path | None

Filename or filepath where the figure is saved.

None
show bool

If True, show the plot.

False
close bool

If True, closes the figure.

False
verbose bool

Print results to stdout.

False
kwargs

Additional keyword arguments for matplotlib.pyplot.imshow.

{}
Source code in skais_mapper/plotting.py
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
254
255
256
257
258
259
260
261
262
263
@singledispatch
@alias_kw("colormap", "cmap")
@alias_kw("colorbar", "cbar")
@alias_kw("colorbar_label", "cbar_label")
def plot_image(
    data: Any,
    batch_idx: int | None = None,
    extent: Sequence[float] | None = None,
    colormap: None = None,
    colorbar: bool = False,
    colorbar_label: str | None = None,
    xlabel: str | None = None,
    ylabel: str | None = None,
    savefig: bool = False,
    path: str | Path | None = None,
    show: bool = False,
    close: bool = False,
    verbose: bool = False,
    **kwargs,
):
    """Plot map from an array, tensor, or batch(es).

    Args:
        data: Array(s) of a map (or maps).
        batch_idx: If not `None`, data is a single or multiple batches of images.
        info: Supplementary information about the data.
        extent: Extent of the map in physical units.
        colormap: Name of the colormap to use for plotting.
        colorbar: If `True`, include the colorbar in the plot.
        colorbar_label: Label of the colorbar (if enabled).
        xlabel: Label of the x-axis.
        ylabel: Label of the y-axis.
        savefig: If `True`, save the plot to file.
        path: Filename or filepath where the figure is saved.
        show: If `True`, show the plot.
        close: If `True`, closes the figure.
        verbose: Print results to stdout.
        kwargs: Additional keyword arguments for `matplotlib.pyplot.imshow`.
    """
    raise NotImplementedError(f"Invalid data type {type(data)}.")

plot_image_array

plot_image_array(
    data: np.ndarray,
    batch_idx: int | Sequence[int] | None = None,
    extent: Sequence[float] | None = None,
    colormap: Colormap | None = None,
    colorbar: bool = False,
    colorbar_label: str | None = None,
    xlabel: str | None = None,
    ylabel: str | None = None,
    savefig: bool = False,
    path: str | Path | None = None,
    show: bool = False,
    close: bool = False,
    verbose: bool = False,
    **kwargs,
)

Plot map from an array or batch(es).

Parameters:

Name Type Description Default
data np.ndarray

Array(s) of a map (or maps)

required
batch_idx int | Sequence[int] | None

If not None, data is a single or multiple batches of images.

None
info

Supplementary information about the data.

required
extent Sequence[float] | None

Extent of the map in physical units.

None
colormap Colormap | None

Name of the colormap to use for plotting.

None
colorbar bool

If True, include the colorbar in the plot.

False
colorbar_label str | None

Label of the colorbar (if enabled).

None
xlabel str | None

Label of the x-axis.

None
ylabel str | None

Label of the y-axis.

None
savefig bool

If True, save the plot to file.

False
path str | Path | None

Filename or filepath where the figure is saved.

None
show bool

If True, show the plot.

False
close bool

If True, closes the figure.

False
verbose bool

Print results to stdout.

False
kwargs

Additional keyword arguments for matplotlib.pyplot.imshow.

{}
Source code in skais_mapper/plotting.py
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
@plot_image.register(np.ndarray)
@alias_kw("colormap", "cmap")
@alias_kw("colorbar", "cbar")
@alias_kw("cbar_label", "colorbar_label")
def plot_image_array(
    data: np.ndarray,
    batch_idx: int | Sequence[int] | None = None,
    extent: Sequence[float] | None = None,
    colormap: Colormap | None = None,
    colorbar: bool = False,
    colorbar_label: str | None = None,
    xlabel: str | None = None,
    ylabel: str | None = None,
    savefig: bool = False,
    path: str | Path | None = None,
    show: bool = False,
    close: bool = False,
    verbose: bool = False,
    **kwargs,
):
    """Plot map from an array or batch(es).

    Args:
        data: Array(s) of a map (or maps)
        batch_idx: If not `None`, data is a single or multiple batches of images.
        info: Supplementary information about the data.
        extent: Extent of the map in physical units.
        colormap: Name of the colormap to use for plotting.
        colorbar: If `True`, include the colorbar in the plot.
        colorbar_label: Label of the colorbar (if enabled).
        xlabel: Label of the x-axis.
        ylabel: Label of the y-axis.
        savefig: If `True`, save the plot to file.
        path: Filename or filepath where the figure is saved.
        show: If `True`, show the plot.
        close: If `True`, closes the figure.
        verbose: Print results to stdout.
        kwargs: Additional keyword arguments for `matplotlib.pyplot.imshow`.
    """
    metadata = kwargs.pop("info", {})
    data, metadata = _from_batch(data, metadata=metadata, batch_idx=batch_idx)
    _plot_data(
        data,
        metadata,
        extent=extent,
        colormap=colormap,
        colorbar=colorbar,
        colorbar_label=colorbar_label,
        xlabel=xlabel,
        ylabel=ylabel,
        savefig=savefig,
        path=path,
        show=show,
        close=close,
        verbose=verbose,
        **kwargs,
    )

plot_image_from_batch

plot_image_from_batch(
    data: Sequence[Tensor | np.ndarray | dict],
    batch_idx: int | Sequence[int] | None = None,
    extent: Sequence[float] | None = None,
    colormap: None = None,
    colorbar: bool = False,
    colorbar_label: str | None = None,
    xlabel: str | None = None,
    ylabel: str | None = None,
    savefig: bool = False,
    path: str | Path | None = None,
    show: bool = False,
    close: bool = False,
    verbose: bool = False,
    **kwargs,
)

Plot map from an array/tensor batch (optionally including metadata).

Parameters:

Name Type Description Default
data Sequence[Tensor | np.ndarray | dict]

Array(s) of a map (or maps)

required
batch_idx int | Sequence[int] | None

If not None, data is a single or multiple batches of images.

None
info

Supplementary information about the data.

required
extent Sequence[float] | None

Extent of the map in physical units.

None
colormap None

Name of the colormap to use for plotting.

None
colorbar bool

If True, include the colorbar in the plot.

False
colorbar_label str | None

Label of the colorbar (if enabled).

None
xlabel str | None

Label of the x-axis.

None
ylabel str | None

Label of the y-axis.

None
savefig bool

If True, save the plot to file.

False
path str | Path | None

Filename or filepath where the figure is saved.

None
show bool

If True, show the plot.

False
close bool

If True, closes the figure.

False
verbose bool

Print results to stdout.

False
kwargs

Additional keyword arguments for matplotlib.pyplot.imshow.

{}
Source code in skais_mapper/plotting.py
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
@plot_image.register(Sequence)
@alias_kw("colormap", "cmap")
@alias_kw("colorbar", "cbar")
@alias_kw("cbar_label", "colorbar_label")
def plot_image_from_batch(
    data: Sequence[Tensor | np.ndarray | dict],
    batch_idx: int | Sequence[int] | None = None,
    extent: Sequence[float] | None = None,
    colormap: None = None,
    colorbar: bool = False,
    colorbar_label: str | None = None,
    xlabel: str | None = None,
    ylabel: str | None = None,
    savefig: bool = False,
    path: str | Path | None = None,
    show: bool = False,
    close: bool = False,
    verbose: bool = False,
    **kwargs,
):
    """Plot map from an array/tensor batch (optionally including metadata).

    Args:
        data: Array(s) of a map (or maps)
        batch_idx: If not `None`, data is a single or multiple batches of images.
        info: Supplementary information about the data.
        extent: Extent of the map in physical units.
        colormap: Name of the colormap to use for plotting.
        colorbar: If `True`, include the colorbar in the plot.
        colorbar_label: Label of the colorbar (if enabled).
        xlabel: Label of the x-axis.
        ylabel: Label of the y-axis.
        savefig: If `True`, save the plot to file.
        path: Filename or filepath where the figure is saved.
        show: If `True`, show the plot.
        close: If `True`, closes the figure.
        verbose: Print results to stdout.
        kwargs: Additional keyword arguments for `matplotlib.pyplot.imshow`.
    """
    if all([isinstance(d, Tensor) or isinstance(d, np.ndarray) for d in data]):
        data = data
        metadata = {}
    else:
        data, metadata = data
    metadata = kwargs.pop("info", metadata)
    data, metadata = _from_batch(data, metadata, batch_idx=batch_idx)
    _plot_data(
        data,
        metadata,
        extent=extent,
        colormap=colormap,
        colorbar=colorbar,
        colorbar_label=colorbar_label,
        xlabel=xlabel,
        ylabel=ylabel,
        savefig=savefig,
        path=path,
        show=show,
        close=close,
        verbose=verbose,
        **kwargs,
    )

plot_image_quantity

plot_image_quantity(
    data: au.Quantity,
    batch_idx: int | Sequence[int] | None = None,
    extent: Sequence[float] | None = None,
    colormap: Colormap | None = None,
    colorbar: bool = False,
    colorbar_label: str | None = None,
    xlabel: str | None = None,
    ylabel: str | None = None,
    savefig: bool = False,
    path: str | Path | None = None,
    show: bool = False,
    close: bool = False,
    verbose: bool = False,
    **kwargs,
)

Plot map from an astropy.units.Quantity array or batch(es).

Parameters:

Name Type Description Default
data au.Quantity

Array(s) of a map (or maps)

required
batch_idx int | Sequence[int] | None

If not None, data is a single or multiple batches of images.

None
info

Supplementary information about the data.

required
extent Sequence[float] | None

Extent of the map in physical units.

None
colormap Colormap | None

Name of the colormap to use for plotting.

None
colorbar bool

If True, include the colorbar in the plot.

False
colorbar_label str | None

Label of the colorbar (if enabled).

None
xlabel str | None

Label of the x-axis.

None
ylabel str | None

Label of the y-axis.

None
savefig bool

If True, save the plot to file.

False
path str | Path | None

Filename or filepath where the figure is saved.

None
show bool

If True, show the plot.

False
close bool

If True, closes the figure.

False
verbose bool

Print results to stdout.

False
kwargs

Additional keyword arguments for matplotlib.pyplot.imshow.

{}
Source code in skais_mapper/plotting.py
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
@plot_image.register(au.Quantity)
@alias_kw("colormap", "cmap")
@alias_kw("colorbar", "cbar")
@alias_kw("cbar_label", "colorbar_label")
def plot_image_quantity(
    data: au.Quantity,
    batch_idx: int | Sequence[int] | None = None,
    extent: Sequence[float] | None = None,
    colormap: Colormap | None = None,
    colorbar: bool = False,
    colorbar_label: str | None = None,
    xlabel: str | None = None,
    ylabel: str | None = None,
    savefig: bool = False,
    path: str | Path | None = None,
    show: bool = False,
    close: bool = False,
    verbose: bool = False,
    **kwargs,
):
    """Plot map from an astropy.units.Quantity array or batch(es).

    Args:
        data: Array(s) of a map (or maps)
        batch_idx: If not `None`, data is a single or multiple batches of images.
        info: Supplementary information about the data.
        extent: Extent of the map in physical units.
        colormap: Name of the colormap to use for plotting.
        colorbar: If `True`, include the colorbar in the plot.
        colorbar_label: Label of the colorbar (if enabled).
        xlabel: Label of the x-axis.
        ylabel: Label of the y-axis.
        savefig: If `True`, save the plot to file.
        path: Filename or filepath where the figure is saved.
        show: If `True`, show the plot.
        close: If `True`, closes the figure.
        verbose: Print results to stdout.
        kwargs: Additional keyword arguments for `matplotlib.pyplot.imshow`.
    """
    metadata = kwargs.pop("info", {})
    data, metadata = _from_batch(data, metadata=metadata, batch_idx=batch_idx)
    data, units = data.value, data.unit
    if "units" not in metadata:
        metadata["units"] = f"{units:latex}"
    _plot_data(
        data,
        metadata,
        extent=extent,
        colormap=colormap,
        colorbar=colorbar,
        colorbar_label=colorbar_label,
        xlabel=xlabel,
        ylabel=ylabel,
        savefig=savefig,
        path=path,
        show=show,
        close=close,
        verbose=verbose,
        **kwargs,
    )

plot_image_tensor

plot_image_tensor(
    data: Tensor,
    batch_idx: int | Sequence[int] | None = None,
    extent: Sequence[float] | None = None,
    colormap: Colormap | None = None,
    colorbar: bool = False,
    colorbar_label: str | None = None,
    xlabel: str | None = None,
    ylabel: str | None = None,
    savefig: bool = False,
    path: str | Path | None = None,
    show: bool = False,
    close: bool = False,
    verbose: bool = False,
    **kwargs,
)

Plot map from a tensor, or batch(es).

Parameters:

Name Type Description Default
data Tensor

Array(s) of a map (or maps)

required
batch_idx int | Sequence[int] | None

If not None, data is a single or multiple batches of images.

None
info

Supplementary information about the data.

required
extent Sequence[float] | None

Extent of the map in physical units.

None
colormap Colormap | None

Name of the colormap to use for plotting.

None
colorbar bool

If True, include the colorbar in the plot.

False
colorbar_label str | None

Label of the colorbar (if enabled).

None
xlabel str | None

Label of the x-axis.

None
ylabel str | None

Label of the y-axis.

None
savefig bool

If True, save the plot to file.

False
path str | Path | None

Filename or filepath where the figure is saved.

None
show bool

If True, show the plot.

False
close bool

If True, closes the figure.

False
verbose bool

Print results to stdout.

False
kwargs

Additional keyword arguments for matplotlib.pyplot.imshow.

{}
Source code in skais_mapper/plotting.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
@plot_image.register(Tensor)
@alias_kw("colormap", "cmap")
@alias_kw("colorbar", "cbar")
@alias_kw("colorbar_label", "cbar_label")
def plot_image_tensor(
    data: Tensor,
    batch_idx: int | Sequence[int] | None = None,
    extent: Sequence[float] | None = None,
    colormap: Colormap | None = None,
    colorbar: bool = False,
    colorbar_label: str | None = None,
    xlabel: str | None = None,
    ylabel: str | None = None,
    savefig: bool = False,
    path: str | Path | None = None,
    show: bool = False,
    close: bool = False,
    verbose: bool = False,
    **kwargs,
):
    """Plot map from a tensor, or batch(es).

    Args:
        data: Array(s) of a map (or maps)
        batch_idx: If not `None`, data is a single or multiple batches of images.
        info: Supplementary information about the data.
        extent: Extent of the map in physical units.
        colormap: Name of the colormap to use for plotting.
        colorbar: If `True`, include the colorbar in the plot.
        colorbar_label: Label of the colorbar (if enabled).
        xlabel: Label of the x-axis.
        ylabel: Label of the y-axis.
        savefig: If `True`, save the plot to file.
        path: Filename or filepath where the figure is saved.
        show: If `True`, show the plot.
        close: If `True`, closes the figure.
        verbose: Print results to stdout.
        kwargs: Additional keyword arguments for `matplotlib.pyplot.imshow`.
    """
    metadata = kwargs.pop("info", {})
    data, metadata = _from_batch(data, metadata=metadata, batch_idx=batch_idx)
    _plot_data(
        data,
        metadata,
        extent=extent,
        colormap=colormap,
        colorbar=colorbar,
        colorbar_label=colorbar_label,
        xlabel=xlabel,
        ylabel=ylabel,
        savefig=savefig,
        path=path,
        show=show,
        close=close,
        verbose=verbose,
        **kwargs,
    )