Source code for torx.plotting.colormaps_m
"""Functionalities related to colormaps."""
import matplotlib.pyplot as plt
import matplotlib.collections as mplcol
_cmap_oneside = "plasma"
_cmap_twoside = "RdBu_r"
[docs]
def set_cmap_oneside(value: str):
"""Set the default colormap for one sided plots."""
global _cmap_oneside
assert value in plt.colormaps(), \
f"Value {value} not in matplotlib colormaps!"
_cmap_oneside = value
[docs]
def set_cmap_twoside(value: str):
"""Set the default colormap for two sided plots."""
global _cmap_twoside
assert value in plt.colormaps(), \
f"Value {value} not in matplotlib colormaps!"
_cmap_twoside = value
[docs]
def colormap(qm: mplcol.QuadMesh):
"""
Set the colormap automatically for the provided quadmesh object.
Choose the best colormap dependent on the color limits of qm.
Detects if limits are one- or two-sided and picks the currently
set cmap values for that.
"""
zl = qm.get_clim()
# One-sided plot
if(zl[0] >= 0.0):
qm.set_cmap(_cmap_oneside)
# Two-sided plot
else:
qm.set_cmap(_cmap_twoside)