Mizani
Mizani is a Python library that provides a comprehensive set of 'scales' for graphics systems, mirroring the functionality of Hadley Wickham's popular R Scales package. It offers tools for data transformation, calculating aesthetically pleasing breaks for axes, and generating color palettes. The current version is 0.14.4, with releases occurring periodically, often in conjunction with Python version updates or fixes.
Warnings
- gotcha The `mizani.transforms` module, which handles time-related transformations, may raise a `ModuleNotFoundError` for `tzdata` on certain platforms (e.g., Pyodide or some Windows setups) if the system does not provide `tzdata`. This is because Python's `zoneinfo` module, used by `mizani`, relies on system `tzdata`.
- gotcha Mizani is a foundational library for constructing graphic scales, not a high-level plotting library itself. While it provides powerful components, direct usage often requires integration with a graphics system (like `plotnine`) rather than producing standalone plots directly. Users expecting immediate plot generation might find it requires more setup.
Install
-
pip install mizani
Imports
- breaks_log
from mizani.breaks import breaks_log
- rescale
from mizani.bounds import rescale
- gradient_n_pal
from mizani.palettes import gradient_n_pal
Quickstart
import numpy as np
from mizani.breaks import breaks_log
# Define a range of data, e.g., from a logarithmic distribution
x = np.logspace(3, 6, 100) # 100 points from 10^3 to 10^6
limits = min(x), max(x)
# Calculate logarithmic breaks for the given limits
log_breaks = breaks_log()(limits)
print(f"Data limits: {limits}")
print(f"Calculated logarithmic breaks: {log_breaks}")
# You can also specify a base for the logarithm
log_breaks_base2 = breaks_log(base=2)(limits)
print(f"Calculated base-2 logarithmic breaks: {log_breaks_base2}")