teilab.utils.plot_utils module¶
- teilab.utils.plot_utils.get_colorList(n: int, cmap: Optional[Union[str, matplotlib.colors.Colormap]] = None, style: str = 'matplotlib') List[Tuple[float, float, float, float]] [source]¶
Get a color List using matplotlib’s colormaps. See Choosing Colormaps in Matplotlib <https://matplotlib.org/stable/tutorials/colors/colormaps.html> for details.
- Parameters
n (int) – The number of samples
cmap (Optional[Union[str,Colormap]], optional) – A
Colormap
object or a color map name. Defaults toNone
.style (str) – How to express colors (Please choose from
"matplotlib"
, or"plotly"
)
- Returns
Color List
- Return type
List[Tuple[float,float,float,float]]
Examples
>>> import matplotlib >>> from matplotlib.cm import _cmap_registry >>> from teilab.utils import get_colorList >>> get_colorList(n=3, cmap="bwr") [(0.6666666666666666, 0.6666666666666666, 1.0, 1.0), (1.0, 0.6666666666666667, 0.6666666666666667, 1.0), (1.0, 0.0, 0.0, 1.0)] >>> get_colorList(n=3, cmap=_cmap_registry["bwr"]) [(0.6666666666666666, 0.6666666666666666, 1.0, 1.0), (1.0, 0.6666666666666667, 0.6666666666666667, 1.0), (1.0, 0.0, 0.0, 1.0)] >>> get_colorList(n=3) [(0.190631, 0.407061, 0.556089, 1.0), (0.20803, 0.718701, 0.472873, 1.0), (0.993248, 0.906157, 0.143936, 1.0)] >>> matplotlib.rcParams['image.cmap'] = "bwr" >>> get_colorList(n=3) [(0.6666666666666666, 0.6666666666666666, 1.0, 1.0), (1.0, 0.6666666666666667, 0.6666666666666667, 1.0), (1.0, 0.0, 0.0, 1.0)] >>> get_colorList(n=3, cmap="bwr", style="plotly") ['rgba(170,170,255,1.0)', 'rgba(255,170,170,1.0)', 'rgba(255,0,0,1.0)']
- teilab.utils.plot_utils.subplots_create(nrows: int = 1, ncols: int = 1, sharex: Union[bool, str] = False, sharey: Union[bool, str] = False, style: str = 'matplotlib', **kwargs) Union[Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes], plotly.graph_objs._figure.Figure] [source]¶
Create subplots for each plot style.
- Parameters
nrows (int, optional) – Number of rows of the subplot grid. Defaults to
1
.ncols (int, optional) – Number of columns of the subplot grid. Defaults to
1
.sharex (Union[bool,str], optional) – Controls sharing of properties among x-axes. Defaults to
False
.sharey (Union[bool,str], optional) – Controls sharing of properties among y-axes. Defaults to
False
.style (str, optional) – Plot style. Please choose from
"matplotlib"
, or"plotly"
. Defaults to"matplotlib"
.
- Returns
Subplots to suit each plot style.
- Return type
Union[Tuple[mplFigure,Axes],plotlyFigure]
Examples
>>> from teilab.utils import subplots_create >>> fig,axes = subplots_create(nrows=3, style="matplotlib") >>> fig.__class__ >>> "<class 'matplotlib.figure.Figure'>" >>> str(axes[0].__class__) >>> "<class 'matplotlib.axes._subplots.AxesSubplot'>" >>> fig = subplots_create(nrows=3, style="plotly") >>> str(fig.__class__) >>> "<class 'plotly.graph_objs._figure.Figure'>"
- teilab.utils.plot_utils.trace_transition(from_fig: plotly.graph_objs._figure.Figure, to_fig: plotly.graph_objs._figure.Figure, row: int = 1, col: int = 1) plotly.graph_objs._figure.Figure [source]¶
Trace
Figure
which is created byplotly.express
- Parameters
from_fig (Figure) – Move the trace that exists in this
Figure
.to_fig (Figure) – Move trace to this
Figure
row (int, optional) – Row of subplots. Defaults to
1
.col (int, optional) – Column of subplots. Defaults to
1
.
- Returns
to_fig
withfrom_fig
‘s traces.- Return type
Figure