contextplt package

Submodules

contextplt.main module

class contextplt.main.Date(rotation=90, x_fontsize=10, **kargs)[source]

Bases: Single

option()[source]

This method is for additional graphic setting. See DatePlot for example.

class contextplt.main.MulSingle(index, sharex=None, sharey=None, xlim=None, ylim=None, xlabel=None, ylabel=None, xlabelfontsize=None, ylabelfontsize=None, xtickfontsize=None, ytickfontsize=None, title=None, titlefontsize=None, tight=True, xrotation=None, yrotation=None, xscale=None, yscale=None, xticklabels_show=True, yticklabels_show=True, hide_spines=None, xticks_show=True, yticks_show=True)[source]

Bases: object

Parameters

hide_spines (Optional[List[str]]) – Hide outlines of axes. Takes “right”,”top”,”bottom”,”left” or these list. Also takes “all” to hide outlines and ticks of plot.

hide_spines: Optional[List[str]] = None
index: int
mul: ClassVar[Multiple]
sharex: Optional[Axes] = None
sharey: Optional[Axes] = None
tight: bool = True
title: Optional[str] = None
titlefontsize: Optional[float] = None
xlabel: Optional[str] = None
xlabelfontsize: Optional[float] = None
xlim: Optional[List[float]] = None
xrotation: Optional[int] = None
xscale: Optional[str] = None
xtickfontsize: Optional[float] = None
xticklabels_show: bool = True
xticks_show: bool = True
ylabel: Optional[str] = None
ylabelfontsize: Optional[float] = None
ylim: Optional[List[float]] = None
yrotation: Optional[int] = None
yscale: Optional[str] = None
ytickfontsize: Optional[float] = None
yticklabels_show: bool = True
yticks_show: bool = True
class contextplt.main.Multiple(figsize=(5, 3), dpi=150, grid=(2, 2), suptitle=None, show=True, tight=False, label_outer=False, save_path=None, savefig_kargs=<factory>, mosaic=None, constrained_layout=None, sharex=False, sharey=False)[source]

Bases: object

Create multiple figures in one picture with arguments.

Parameters
  • mosaic (Optional[List]) – Support of matplotlib.pyplot.subplot_mosaic. After specifying this mosaic parameter, access each ax by passing a character in mosaic.

  • sharex (bool) – for mosaic plot.

  • sharey (bool) – for mosaic plot.

Examples

Basic usage.

>>> import numpy as np
>>> import contextplt as cplt
>>> x1, x2, y1, y2= np.random.rand(4, 100)
>>> with cplt.Multiple(grid=(2,1),figsize=(5,4), dpi=150) as mul:
>>>     with mul.Single(index=1) as p:
>>>         p.ax.scatter(x1,y1)
>>>     with mul.Single(index=2) as p:
>>>         p.ax.scatter(x2,y2)

Various options. Label_outer only leaves the outside of ticks and labels.

>>> with cplt.Multiple(grid=(2,2),figsize=(6,4), dpi=150,
...         suptitle="super title", label_outer=True) as mul:
>>>     for i in range(4):
>>>         with mul.Single(index=i+1,xlabel=f"xlabel{i+1}", ylabel=f"ylabel{i+1}") as p:
>>>             x, y = np.random.rand(2,100)
>>>             p.ax.plot(x,y)
constrained_layout: Optional[bool] = None
dpi: int = 150
figsize: Tuple[float, float] = (5, 3)
grid: Tuple[int, int] = (2, 2)
label_outer: bool = False
mosaic: Optional[List] = None
option()[source]

This method is for additional graphic setting. See DatePlot for example.

save_path: Optional[str] = None
savefig_kargs: dict
set_ax(index, xlim=None, ylim=None, xlabel='', ylabel='', title='', rotation=0)[source]

Return axis object.

Parameters

index (int) – index of which axes object is pointed at.

Note

Currently this method is not maintained, and intended to use self.mul attribute to create another figure.

sharex: bool = False
sharey: bool = False
show: bool = True
suptitle: Optional[str] = None
tight: bool = False
class contextplt.main.Single(figsize=(5, 3), dpi=150, xlim=None, ylim=None, xlabel=None, ylabel=None, xlabelfontsize=None, ylabelfontsize=None, xtickfontsize=None, ytickfontsize=None, title=None, titlefontsize=None, tight=True, xrotation=None, yrotation=None, xscale=None, yscale=None, show=True, xticklabels_show=True, yticklabels_show=True, xticks_show=True, yticks_show=True, hide_spines=None, save_path=None, savefig_kargs=<factory>)[source]

Bases: object

Create one figure. Adjust figure with arguments.

Parameters
  • figsize (Tuple[float, float]) – Figure size.

  • dpi (int) – dpi.

  • xlim (Optional[List[float]]) – x limit.

  • ylim (Optional[List[float]]) – y limit.

  • show (bool) – If False, plot is not displayed.

  • xticklabels_show (bool) – If False, y tick labels are hidden.

  • yticklabels_show (bool) – If False, y tick labels are hidden.

  • xtick_show – If False, tick labels and ticks are hidden.

  • ytick_show – If False, tick labels and ticks are hidden.

  • hide_spines (Optional[List[str]]) – Hide outlines of axes. Takes “right”,”top”,”bottom”,”left” or these list. Also takes “all” to hide outlines and ticks of plot.

Examples

Basic usage.

>>> import contextplt as cplt
>>> x = [1,2,3]
>>> y = [1,2,3]
>>> with cplt.Single() as p:
>>>     p.ax.plot(x,y)

With parameter version.

>>> with cplt.Single(xlim=[0,5], ylim=[0,5], xlabel="xlabel", ylabel="ylabel",
...         title="title", figsize=(6,6), dpi=150) as p:
>>>     p.ax.plot(x,y)

Can use variadic keyword arguments to share the same keyword arguments.

>>> kargs = dict(xlim=[0,5], ylim=[0,5], xlabel="xlabel", ylabel="ylabel",
...         title="title", figsize=(6,6), dpi=150)
>>> with cplt.Single(**kargs) as p:
>>>     p.ax.plot(x,y)
dpi: int = 150
figsize: Tuple[float, float] = (5, 3)
hide_spines: Optional[List[str]] = None
option()[source]

This method is for additional graphic setting. See DatePlot for example.

save_path: Optional[str] = None
savefig_kargs: dict
show: bool = True
tight: bool = True
title: Optional[str] = None
titlefontsize: Optional[float] = None
xlabel: Optional[str] = None
xlabelfontsize: Optional[float] = None
xlim: Optional[List[float]] = None
xrotation: Optional[int] = None
xscale: Optional[str] = None
xtickfontsize: Optional[float] = None
xticklabels_show: bool = True
xticks_show: bool = True
ylabel: Optional[str] = None
ylabelfontsize: Optional[float] = None
ylim: Optional[List[float]] = None
yrotation: Optional[int] = None
yscale: Optional[str] = None
ytickfontsize: Optional[float] = None
yticklabels_show: bool = True
yticks_show: bool = True

Module contents

class contextplt.MulSingle(index, sharex=None, sharey=None, xlim=None, ylim=None, xlabel=None, ylabel=None, xlabelfontsize=None, ylabelfontsize=None, xtickfontsize=None, ytickfontsize=None, title=None, titlefontsize=None, tight=True, xrotation=None, yrotation=None, xscale=None, yscale=None, xticklabels_show=True, yticklabels_show=True, hide_spines=None, xticks_show=True, yticks_show=True)[source]

Bases: object

Parameters

hide_spines (Optional[List[str]]) – Hide outlines of axes. Takes “right”,”top”,”bottom”,”left” or these list. Also takes “all” to hide outlines and ticks of plot.

hide_spines: Optional[List[str]] = None
index: int
mul: ClassVar[Multiple]
sharex: Optional[Axes] = None
sharey: Optional[Axes] = None
tight: bool = True
title: Optional[str] = None
titlefontsize: Optional[float] = None
xlabel: Optional[str] = None
xlabelfontsize: Optional[float] = None
xlim: Optional[List[float]] = None
xrotation: Optional[int] = None
xscale: Optional[str] = None
xtickfontsize: Optional[float] = None
xticklabels_show: bool = True
xticks_show: bool = True
ylabel: Optional[str] = None
ylabelfontsize: Optional[float] = None
ylim: Optional[List[float]] = None
yrotation: Optional[int] = None
yscale: Optional[str] = None
ytickfontsize: Optional[float] = None
yticklabels_show: bool = True
yticks_show: bool = True
class contextplt.Multiple(figsize=(5, 3), dpi=150, grid=(2, 2), suptitle=None, show=True, tight=False, label_outer=False, save_path=None, savefig_kargs=<factory>, mosaic=None, constrained_layout=None, sharex=False, sharey=False)[source]

Bases: object

Create multiple figures in one picture with arguments.

Parameters
  • mosaic (Optional[List]) – Support of matplotlib.pyplot.subplot_mosaic. After specifying this mosaic parameter, access each ax by passing a character in mosaic.

  • sharex (bool) – for mosaic plot.

  • sharey (bool) – for mosaic plot.

Examples

Basic usage.

>>> import numpy as np
>>> import contextplt as cplt
>>> x1, x2, y1, y2= np.random.rand(4, 100)
>>> with cplt.Multiple(grid=(2,1),figsize=(5,4), dpi=150) as mul:
>>>     with mul.Single(index=1) as p:
>>>         p.ax.scatter(x1,y1)
>>>     with mul.Single(index=2) as p:
>>>         p.ax.scatter(x2,y2)

Various options. Label_outer only leaves the outside of ticks and labels.

>>> with cplt.Multiple(grid=(2,2),figsize=(6,4), dpi=150,
...         suptitle="super title", label_outer=True) as mul:
>>>     for i in range(4):
>>>         with mul.Single(index=i+1,xlabel=f"xlabel{i+1}", ylabel=f"ylabel{i+1}") as p:
>>>             x, y = np.random.rand(2,100)
>>>             p.ax.plot(x,y)
constrained_layout: Optional[bool] = None
dpi: int = 150
figsize: Tuple[float, float] = (5, 3)
grid: Tuple[int, int] = (2, 2)
label_outer: bool = False
mosaic: Optional[List] = None
option()[source]

This method is for additional graphic setting. See DatePlot for example.

save_path: Optional[str] = None
savefig_kargs: dict
set_ax(index, xlim=None, ylim=None, xlabel='', ylabel='', title='', rotation=0)[source]

Return axis object.

Parameters

index (int) – index of which axes object is pointed at.

Note

Currently this method is not maintained, and intended to use self.mul attribute to create another figure.

sharex: bool = False
sharey: bool = False
show: bool = True
suptitle: Optional[str] = None
tight: bool = False
class contextplt.Single(figsize=(5, 3), dpi=150, xlim=None, ylim=None, xlabel=None, ylabel=None, xlabelfontsize=None, ylabelfontsize=None, xtickfontsize=None, ytickfontsize=None, title=None, titlefontsize=None, tight=True, xrotation=None, yrotation=None, xscale=None, yscale=None, show=True, xticklabels_show=True, yticklabels_show=True, xticks_show=True, yticks_show=True, hide_spines=None, save_path=None, savefig_kargs=<factory>)[source]

Bases: object

Create one figure. Adjust figure with arguments.

Parameters
  • figsize (Tuple[float, float]) – Figure size.

  • dpi (int) – dpi.

  • xlim (Optional[List[float]]) – x limit.

  • ylim (Optional[List[float]]) – y limit.

  • show (bool) – If False, plot is not displayed.

  • xticklabels_show (bool) – If False, y tick labels are hidden.

  • yticklabels_show (bool) – If False, y tick labels are hidden.

  • xtick_show – If False, tick labels and ticks are hidden.

  • ytick_show – If False, tick labels and ticks are hidden.

  • hide_spines (Optional[List[str]]) – Hide outlines of axes. Takes “right”,”top”,”bottom”,”left” or these list. Also takes “all” to hide outlines and ticks of plot.

Examples

Basic usage.

>>> import contextplt as cplt
>>> x = [1,2,3]
>>> y = [1,2,3]
>>> with cplt.Single() as p:
>>>     p.ax.plot(x,y)

With parameter version.

>>> with cplt.Single(xlim=[0,5], ylim=[0,5], xlabel="xlabel", ylabel="ylabel",
...         title="title", figsize=(6,6), dpi=150) as p:
>>>     p.ax.plot(x,y)

Can use variadic keyword arguments to share the same keyword arguments.

>>> kargs = dict(xlim=[0,5], ylim=[0,5], xlabel="xlabel", ylabel="ylabel",
...         title="title", figsize=(6,6), dpi=150)
>>> with cplt.Single(**kargs) as p:
>>>     p.ax.plot(x,y)
dpi: int = 150
figsize: Tuple[float, float] = (5, 3)
hide_spines: Optional[List[str]] = None
option()[source]

This method is for additional graphic setting. See DatePlot for example.

save_path: Optional[str] = None
savefig_kargs: dict
show: bool = True
tight: bool = True
title: Optional[str] = None
titlefontsize: Optional[float] = None
xlabel: Optional[str] = None
xlabelfontsize: Optional[float] = None
xlim: Optional[List[float]] = None
xrotation: Optional[int] = None
xscale: Optional[str] = None
xtickfontsize: Optional[float] = None
xticklabels_show: bool = True
xticks_show: bool = True
ylabel: Optional[str] = None
ylabelfontsize: Optional[float] = None
ylim: Optional[List[float]] = None
yrotation: Optional[int] = None
yscale: Optional[str] = None
ytickfontsize: Optional[float] = None
yticklabels_show: bool = True
yticks_show: bool = True