Skip to content

arkas.plotter

arkas.plotter

Contain data plotters.

arkas.plotter.BaseCachedPlotter

Bases: BasePlotter

Define the base class to implement a plotter that caches the figures after the first generation.

arkas.plotter.BasePlotter

Bases: ABC

Define the base class to implement a plotter.

Example usage:

>>> from arkas.plotter import Plotter
>>> plotter = Plotter()
>>> plotter
Plotter(count=0)
arkas.plotter.BasePlotter.compute abstractmethod
compute() -> BasePlotter

Compute the figures and return a new plotter.

Returns:

Type Description
BasePlotter

A new plotter with the computed figures.

Example usage:

>>> from arkas.plotter import Plotter
>>> plotter = Plotter({"fig": None})
>>> plotter
Plotter(count=1)
>>> plotter2 = plotter.compute()
>>> plotter2
Plotter(count=1)
arkas.plotter.BasePlotter.equal abstractmethod
equal(other: Any, equal_nan: bool = False) -> bool

Indicate if two plotters are equal or not.

Parameters:

Name Type Description Default
other Any

The other plotter to compare.

required
equal_nan bool

Whether to compare NaN's as equal. If True, NaN's in both objects will be considered equal.

False

Returns:

Type Description
bool

True if the two plotters are equal, otherwise False.

Example usage:

>>> from arkas.plotter import Plotter
>>> plotter1 = Plotter()
>>> plotter2 = Plotter()
>>> plotter3 = Plotter({"fig": None})
>>> plotter1.equal(plotter2)
True
>>> plotter1.equal(plotter3)
False
arkas.plotter.BasePlotter.plot abstractmethod
plot(prefix: str = '', suffix: str = '') -> dict

Generate the figures.

Parameters:

Name Type Description Default
prefix str

The key prefix in the returned dictionary.

''
suffix str

The key suffix in the returned dictionary.

''

Returns:

Type Description
dict

A dictionary with the generated figures.

Example usage:

>>> from arkas.plotter import Plotter
>>> plotter = Plotter()
>>> plotter.plot()
{}

arkas.plotter.BaseStateCachedPlotter

Bases: BaseCachedPlotter, Generic[T]

Define the base class to implement a plotter that caches the figures after the first generation, and computes the figures from a state object.

Parameters:

Name Type Description Default
state T

The state with the data.

required

arkas.plotter.ColumnCooccurrencePlotter

Bases: BaseStateCachedPlotter[ColumnCooccurrenceState]

Implement a pairwise column co-occurrence plotter.

Parameters:

Name Type Description Default
state T

The state with the co-occurrence matrix.

required

Example usage:

>>> import numpy as np
>>> from arkas.plotter import ColumnCooccurrencePlotter
>>> from arkas.state import ColumnCooccurrenceState
>>> plotter = ColumnCooccurrencePlotter(
...     ColumnCooccurrenceState(matrix=np.ones((3, 3)), columns=["a", "b", "c"])
... )
>>> plotter
ColumnCooccurrencePlotter(
  (state): ColumnCooccurrenceState(matrix=(3, 3), figure_config=MatplotlibFigureConfig())
)

arkas.plotter.ContinuousSeriesPlotter

Bases: BaseStateCachedPlotter[SeriesState]

Implement a plotter that analyzes a column with continuous values.

Parameters:

Name Type Description Default
state T

The state containing the Series to analyze.

required

Example usage:

>>> import polars as pl
>>> from arkas.plotter import ContinuousSeriesPlotter
>>> from arkas.state import SeriesState
>>> plotter = ContinuousSeriesPlotter(SeriesState(pl.Series("col1", [1, 2, 3, 4, 5, 6, 7])))
>>> plotter
ContinuousSeriesPlotter(
  (state): SeriesState(name='col1', values=(7,), figure_config=MatplotlibFigureConfig())
)

arkas.plotter.CorrelationPlotter

Bases: BaseStateCachedPlotter[TwoColumnDataFrameState]

Implement a DataFrame column plotter.

Parameters:

Name Type Description Default
state TwoColumnDataFrameState

The state containing the DataFrame to analyze. The DataFrame must have only 2 columns, which are the two columns to analyze.

required

Example usage:

>>> import polars as pl
>>> from arkas.plotter import CorrelationPlotter
>>> from arkas.state import TwoColumnDataFrameState
>>> frame = pl.DataFrame(
...     {
...         "col1": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0],
...         "col2": [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0],
...     },
... )
>>> plotter = CorrelationPlotter(
...     TwoColumnDataFrameState(frame, column1="col1", column2="col2")
... )
>>> plotter
CorrelationPlotter(
  (state): TwoColumnDataFrameState(dataframe=(7, 2), column1='col1', column2='col2', nan_policy='propagate', figure_config=MatplotlibFigureConfig())
)

arkas.plotter.HexbinColumnPlotter

Bases: BaseStateCachedPlotter[ScatterDataFrameState]

Implement a DataFrame column plotter that makes a 2D hexagonal binning plot of points x, y.

Parameters:

Name Type Description Default
state T

The state containing the DataFrame to analyze.

required

Example usage:

>>> import polars as pl
>>> from arkas.plotter import HexbinColumnPlotter
>>> from arkas.state import ScatterDataFrameState
>>> frame = pl.DataFrame(
...     {
...         "col1": [1.2, 4.2, 4.2, 2.2],
...         "col2": [1, 1, 1, 1],
...         "col3": [1, 2, 2, 2],
...     },
...     schema={"col1": pl.Float64, "col2": pl.Int64, "col3": pl.Int64},
... )
>>> plotter = HexbinColumnPlotter(
...     ScatterDataFrameState(frame, x="col1", y="col2", color="col3")
... )
>>> plotter
HexbinColumnPlotter(
  (state): ScatterDataFrameState(dataframe=(4, 3), x='col1', y='col2', color='col3', nan_policy='propagate', figure_config=MatplotlibFigureConfig())
)

arkas.plotter.NullValuePlotter

Bases: BaseStateCachedPlotter[NullValueState]

Implement a plotter that plots the number of null values for each column.

Parameters:

Name Type Description Default
state T

The state containing the number of null values per column.

required

Example usage:

>>> import numpy as np
>>> from arkas.plotter import NullValuePlotter
>>> from arkas.state import NullValueState
>>> plotter = NullValuePlotter(
...     NullValueState(
...         null_count=np.array([0, 1, 2]),
...         total_count=np.array([5, 5, 5]),
...         columns=["col1", "col2", "col3"],
...     )
... )
>>> plotter
NullValuePlotter(
  (state): NullValueState(num_columns=3, figure_config=MatplotlibFigureConfig())
)

arkas.plotter.PlotColumnPlotter

Bases: BaseStateCachedPlotter[DataFrameState]

Implement a DataFrame column plotter.

Parameters:

Name Type Description Default
state T

The state containing the DataFrame to analyze.

required

Example usage:

>>> import polars as pl
>>> from arkas.plotter import PlotColumnPlotter
>>> from arkas.state import DataFrameState
>>> frame = pl.DataFrame(
...     {
...         "col1": [1.2, 4.2, 4.2, 2.2],
...         "col2": [1, 1, 1, 1],
...         "col3": [1, 2, 2, 2],
...     },
...     schema={"col1": pl.Float64, "col2": pl.Int64, "col3": pl.Int64},
... )
>>> plotter = PlotColumnPlotter(DataFrameState(frame))
>>> plotter
PlotColumnPlotter(
  (state): DataFrameState(dataframe=(4, 3), nan_policy='propagate', figure_config=MatplotlibFigureConfig())
)

arkas.plotter.Plotter

Bases: BasePlotter

Implement a simple plotter.

Parameters:

Name Type Description Default
figures dict | None

The dictionary of figures.

None

Example usage:

>>> from arkas.plotter import Plotter
>>> plotter = Plotter()
>>> plotter
Plotter(count=0)
>>> plotter.plot()
{}

arkas.plotter.PlotterDict

Bases: BasePlotter

Implement a plotter that generates figures from a mapping of plotters.

Parameters:

Name Type Description Default
plotters Mapping[Hashable, BasePlotter]

The mapping of plotters.

required

Example usage:

>>> from arkas.plotter import PlotterDict, Plotter
>>> plotter = PlotterDict(
...     {
...         "one": Plotter(),
...         "two": Plotter({"fig": None}),
...     }
... )
>>> plotter
PlotterDict(
  (one): Plotter(count=0)
  (two): Plotter(count=1)
)
>>> figures = plotter.plot()
>>> figures
{'one': {}, 'two': {'fig': None}}

arkas.plotter.ScatterColumnPlotter

Bases: BaseStateCachedPlotter[ScatterDataFrameState]

Implement a DataFrame column plotter.

Parameters:

Name Type Description Default
state T

The state containing the DataFrame to analyze.

required

Example usage:

>>> import polars as pl
>>> from arkas.plotter import ScatterColumnPlotter
>>> from arkas.state import ScatterDataFrameState
>>> frame = pl.DataFrame(
...     {
...         "col1": [1.2, 4.2, 4.2, 2.2],
...         "col2": [1, 1, 1, 1],
...         "col3": [1, 2, 2, 2],
...     },
...     schema={"col1": pl.Float64, "col2": pl.Int64, "col3": pl.Int64},
... )
>>> plotter = ScatterColumnPlotter(
...     ScatterDataFrameState(frame, x="col1", y="col2", color="col3")
... )
>>> plotter
ScatterColumnPlotter(
  (state): ScatterDataFrameState(dataframe=(4, 3), x='col1', y='col2', color='col3', nan_policy='propagate', figure_config=MatplotlibFigureConfig())
)

arkas.plotter.TemporalNullValuePlotter

Bases: BaseStateCachedPlotter[TemporalDataFrameState]

Implement a DataFrame column plotter.

Parameters:

Name Type Description Default
state T

The state containing the DataFrame to analyze.

required

Example usage:

>>> from datetime import datetime, timezone
>>> import polars as pl
>>> from arkas.plotter import TemporalNullValuePlotter
>>> from arkas.state import TemporalDataFrameState
>>> frame = pl.DataFrame(
...     {
...         "col1": [0, 1, 1, 0],
...         "col2": [0, 1, 0, 1],
...         "col3": [1, 0, 0, 0],
...         "datetime": [
...             datetime(year=2020, month=1, day=3, tzinfo=timezone.utc),
...             datetime(year=2020, month=2, day=3, tzinfo=timezone.utc),
...             datetime(year=2020, month=3, day=3, tzinfo=timezone.utc),
...             datetime(year=2020, month=4, day=3, tzinfo=timezone.utc),
...         ],
...     },
...     schema={
...         "col1": pl.Int64,
...         "col2": pl.Int64,
...         "col3": pl.Int64,
...         "datetime": pl.Datetime(time_unit="us", time_zone="UTC"),
...     },
... )
>>> plotter = TemporalNullValuePlotter(
...     TemporalDataFrameState(frame, temporal_column="datetime", period="1d")
... )
>>> plotter
TemporalNullValuePlotter(
  (state): TemporalDataFrameState(dataframe=(4, 4), temporal_column='datetime', period='1d', nan_policy='propagate', figure_config=MatplotlibFigureConfig())
)

arkas.plotter.TemporalPlotColumnPlotter

Bases: BaseStateCachedPlotter[TemporalDataFrameState]

Implement a DataFrame column plotter.

Parameters:

Name Type Description Default
state T

The state containing the DataFrame to analyze.

required

Example usage:

>>> from datetime import datetime, timezone
>>> import polars as pl
>>> from arkas.plotter import TemporalPlotColumnPlotter
>>> from arkas.state import TemporalDataFrameState
>>> frame = pl.DataFrame(
...     {
...         "col1": [0, 1, 1, 0],
...         "col2": [0, 1, 0, 1],
...         "col3": [1, 0, 0, 0],
...         "datetime": [
...             datetime(year=2020, month=1, day=3, tzinfo=timezone.utc),
...             datetime(year=2020, month=2, day=3, tzinfo=timezone.utc),
...             datetime(year=2020, month=3, day=3, tzinfo=timezone.utc),
...             datetime(year=2020, month=4, day=3, tzinfo=timezone.utc),
...         ],
...     },
...     schema={
...         "col1": pl.Int64,
...         "col2": pl.Int64,
...         "col3": pl.Int64,
...         "datetime": pl.Datetime(time_unit="us", time_zone="UTC"),
...     },
... )
>>> plotter = TemporalPlotColumnPlotter(
...     TemporalDataFrameState(frame, temporal_column="datetime")
... )
>>> plotter
TemporalPlotColumnPlotter(
  (state): TemporalDataFrameState(dataframe=(4, 4), temporal_column='datetime', period=None, nan_policy='propagate', figure_config=MatplotlibFigureConfig())
)