plot-io 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. plot_io/__init__.py +66 -0
  2. plot_io/_backend.py +114 -0
  3. plot_io/axis.py +574 -0
  4. plot_io/colorbar.py +342 -0
  5. plot_io/decorations.py +496 -0
  6. plot_io/defaults.py +766 -0
  7. plot_io/density.py +97 -0
  8. plot_io/enums.py +63 -0
  9. plot_io/facets.py +184 -0
  10. plot_io/figure.py +331 -0
  11. plot_io/labels.py +63 -0
  12. plot_io/legend.py +498 -0
  13. plot_io/limits.py +92 -0
  14. plot_io/maps/__init__.py +365 -0
  15. plot_io/maps/data.py +333 -0
  16. plot_io/markers.py +117 -0
  17. plot_io/numbers.py +289 -0
  18. plot_io/occupancy.py +219 -0
  19. plot_io/palettes.py +142 -0
  20. plot_io/plot.py +435 -0
  21. plot_io/render.py +1122 -0
  22. plot_io/scales.py +93 -0
  23. plot_io/series/__init__.py +498 -0
  24. plot_io/series/area.py +181 -0
  25. plot_io/series/bar.py +294 -0
  26. plot_io/series/box.py +401 -0
  27. plot_io/series/catdata.py +23 -0
  28. plot_io/series/catpoints.py +182 -0
  29. plot_io/series/contour.py +294 -0
  30. plot_io/series/curves.py +128 -0
  31. plot_io/series/ecdf.py +143 -0
  32. plot_io/series/errorbar.py +111 -0
  33. plot_io/series/errors.py +100 -0
  34. plot_io/series/fill.py +168 -0
  35. plot_io/series/heatmap.py +304 -0
  36. plot_io/series/hexbin.py +216 -0
  37. plot_io/series/hist.py +379 -0
  38. plot_io/series/hist2d.py +163 -0
  39. plot_io/series/kde.py +228 -0
  40. plot_io/series/kde2d.py +153 -0
  41. plot_io/series/line.py +173 -0
  42. plot_io/series/pie.py +304 -0
  43. plot_io/series/points.py +341 -0
  44. plot_io/series/regression.py +250 -0
  45. plot_io/series/scatter.py +103 -0
  46. plot_io/series/stem.py +112 -0
  47. plot_io/series/violin.py +321 -0
  48. plot_io/settings.py +281 -0
  49. plot_io/shapes.py +57 -0
  50. plot_io/sharing.py +160 -0
  51. plot_io/slots.py +52 -0
  52. plot_io/stacking.py +63 -0
  53. plot_io/stats.py +140 -0
  54. plot_io/style.py +71 -0
  55. plot_io/styles/__init__.py +234 -0
  56. plot_io/styles/library.py +732 -0
  57. plot_io/tables.py +141 -0
  58. plot_io/text.py +109 -0
  59. plot_io/ticks.py +284 -0
  60. plot_io/times.py +199 -0
  61. plot_io/values.py +161 -0
  62. plot_io-0.1.0.dist-info/METADATA +102 -0
  63. plot_io-0.1.0.dist-info/RECORD +65 -0
  64. plot_io-0.1.0.dist-info/WHEEL +4 -0
  65. plot_io-0.1.0.dist-info/licenses/LICENSE +28 -0
plot_io/__init__.py ADDED
@@ -0,0 +1,66 @@
1
+ """plot_io: plots for PDF, PNG and JPEG, drawn with pdf_io.
2
+
3
+ Basic usage::
4
+
5
+ import plot_io as pl
6
+
7
+ s = pl.Scatter(x, y, color="C1")
8
+ s.plot.x_axis(label="Time (s)")
9
+ s.plot.save("scatter.pdf")
10
+ """
11
+
12
+ from pdf_io import Span
13
+
14
+ from .colorbar import Colorbar
15
+ from .density import Density
16
+ from .facets import FacetFigure, facet
17
+ from .enums import Align, LineStyle, Marker, Order, Orientation, Position, Scale
18
+ from .figure import Figure
19
+ from .maps import ColorMap, SizeMap, color_map_names, register_color_map
20
+ from .markers import marker_area, marker_path, register_marker
21
+ from .palettes import palette_names, register_palette
22
+ from .plot import Plot
23
+ from .series import Series
24
+ from .series.area import Area
25
+ from .series.bar import Bar
26
+ from .series.box import Box
27
+ from .series.ecdf import Ecdf
28
+ from .series.errorbar import Errorbar
29
+ from .series.catpoints import Strip, Swarm
30
+ from .series.contour import Contour
31
+ from .series.hexbin import Hexbin
32
+ from .series.hist import Hist
33
+ from .series.hist2d import Hist2d
34
+ from .series.kde import Kde
35
+ from .series.kde2d import Kde2d
36
+ from .series.pie import Pie
37
+ from .series.regression import Regression
38
+ from .series.violin import Violin
39
+ from .series.stem import Stem
40
+ from .series.errors import ErrorBars
41
+ from .series.fill import Fill
42
+ from .series.heatmap import Heatmap
43
+ from .series.line import Line
44
+ from .series.scatter import Scatter
45
+ from .defaults import DEFAULTS
46
+ from .settings import THEME
47
+ from .style import PALETTE
48
+ from .tables import SeriesGroup
49
+ from .styles import register_style, set_style, style_settings, styles, use_style
50
+
51
+ __all__ = ["Figure", "Plot", "Scatter", "Line", "Fill", "Box", "Heatmap", "Series", "Colorbar",
52
+ "Bar", "Hist", "Ecdf", "Kde2d", "Stem", "Errorbar", "Area", "Kde", "Violin", "Strip",
53
+ "Swarm", "Regression", "Hist2d", "Hexbin", "Contour", "Pie",
54
+ "ColorMap", "SizeMap", "Density", "facet", "FacetFigure", "SeriesGroup", "ErrorBars", "Span", "register_color_map", "color_map_names",
55
+ "register_marker", "marker_path", "marker_area", "Marker", "LineStyle",
56
+ "Orientation", "Scale", "Position", "Order", "Align", "PALETTE", "THEME", "defaults",
57
+ "register_style", "set_style", "use_style", "styles", "style_settings",
58
+ "register_palette", "palette_names",
59
+ "__version__"]
60
+
61
+ __version__ = "0.1.0"
62
+
63
+
64
+ def defaults() -> dict:
65
+ """A copy of every default setting (:data:`plot_io.defaults.DEFAULTS`)."""
66
+ return dict(DEFAULTS)
plot_io/_backend.py ADDED
@@ -0,0 +1,114 @@
1
+ """The pdf_io calls plot_io relies on, in one place.
2
+
3
+ Array helpers (``scaled``, ``extent``, ``quantiles``, ``box_stats``), text metrics and the
4
+ conversion of plot_io's color maps to pdf_io's.
5
+ """
6
+
7
+ import contextlib
8
+ import contextvars
9
+ from collections.abc import Iterator, Sequence
10
+ from typing import Any
11
+
12
+ import pdf_io
13
+ from pdf_io import arrays as _arrays
14
+
15
+ __all__ = ["doubles", "scaled", "extent", "quantiles", "box_stats", "text_extent",
16
+ "simplify_arg", "pdf_color_map", "colors_at", "path_area"]
17
+
18
+ doubles = _arrays.doubles
19
+ box_stats = _arrays.box_stats
20
+
21
+
22
+ def scaled(values: Any, scale: float = 1.0, offset: float = 0.0, function: Any = None,
23
+ linthresh: float = 1.0, **kw: Any) -> Any:
24
+ """pdf_io's ``arrays.scaled`` (``linthresh``: the linear region of ``symlog``)."""
25
+ if function == "symlog":
26
+ kw["linthresh"] = linthresh
27
+ return _arrays.scaled(values, scale, offset, function, **kw)
28
+
29
+
30
+ def extent(values: Any, function: Any = None) -> Any:
31
+ return _arrays.extent(values, function)
32
+
33
+
34
+ def quantiles(values: Any, qs: Sequence[float]) -> list[float]:
35
+ """Quantiles by linear interpolation (numpy's default)."""
36
+ return list(_arrays.quantiles(values, qs))
37
+
38
+
39
+ def text_extent(canvas: Any, content: Any) -> tuple[float, float, float]:
40
+ """``(width, ascent, descent)`` of one line of text with the canvas font settings."""
41
+ return canvas.text_extent(content)
42
+
43
+
44
+ _IMAGE_OUTPUT = contextvars.ContextVar("plot_io_image_output", default=False)
45
+
46
+
47
+ @contextlib.contextmanager
48
+ def image_output() -> Iterator[None]:
49
+ """Drawing for PNG, JPEG or JPEG XL output (see :func:`simplify_arg`)."""
50
+ token = _IMAGE_OUTPUT.set(True)
51
+ try:
52
+ yield
53
+ finally:
54
+ _IMAGE_OUTPUT.reset(token)
55
+
56
+
57
+ def simplify_arg(value: Any, lines: bool = False) -> Any:
58
+ """``value`` as pdf_io's ``simplify`` argument. For image output nothing is culled:
59
+ rasterizing hidden content costs less than culling it and gives the same pixels.
60
+ Lines and areas (``lines``) are still decimated where they are dense (``"auto"``)."""
61
+ if value is None or value is False or not _IMAGE_OUTPUT.get():
62
+ return value
63
+ return "auto" if lines else False
64
+
65
+
66
+ def pdf_color_map(stops: Sequence[tuple[float, tuple[float, ...]]], interpolation: str = "linear",
67
+ under: Any = None, over: Any = None, bad: Any = None) -> Any:
68
+ """pdf_io's color map for stops ``(position, rgba)``. Steps start at their stop;
69
+ pdf_io's ``nearest`` takes the nearest stop, so step maps pass their step centres."""
70
+ if interpolation == "nearest":
71
+ ends = [p for p, _ in stops[1:]] + [1.0]
72
+ stops = [((p + e) / 2, c) for (p, c), e in zip(stops, ends)]
73
+ return pdf_io.ColorMap(list(stops), interpolation=interpolation, under=under, over=over,
74
+ bad=bad)
75
+
76
+
77
+ def colors_at(pdf_map: Any, ts: Any) -> Any:
78
+ """Colors of a pdf_io color map at many positions, as an ``(n, 4)`` buffer."""
79
+ flat = pdf_map.colors_at(ts)
80
+ n = len(flat) // 4
81
+ return memoryview(flat).cast("B").cast("d", (n, 4)) if n else []
82
+
83
+
84
+ def path_area(path: Any) -> float:
85
+ """Filled area of a ``pdf_io.Path`` (nonzero winding)."""
86
+ return float(path.area())
87
+
88
+
89
+ # ---------------------------------------------------------------------------
90
+ # 2-D density and argsort
91
+ # ---------------------------------------------------------------------------
92
+
93
+ def kde2d_bandwidth(xs: Any, ys: Any, rule: str = "scott") -> tuple[float, float, float]:
94
+ """scipy's kernel covariance ``(h11, h12, h22)`` for points ``(xs, ys)`` (NaN for fewer
95
+ than two distinct points)."""
96
+ h = _arrays.kde2d_bandwidth(xs, ys, rule)
97
+ return (float(h[0]), float(h[1]), float(h[2]))
98
+
99
+
100
+ def kde2d_at(xs: Any, ys: Any, h: tuple[float, float, float], method: str = "auto",
101
+ grid: int = 512) -> Any:
102
+ """The 2-D Gaussian density (kernel covariance ``h``) at each point."""
103
+ return _arrays.kde2d_at(xs, ys, h, method=method, grid=grid)
104
+
105
+
106
+ def kde2d_grid(xs: Any, ys: Any, h: tuple[float, float, float], x0: float, x1: float, nx: int,
107
+ y0: float, y1: float, ny: int) -> Any:
108
+ """The density on an ``ny × nx`` grid of nodes from ``(x0, y0)`` to ``(x1, y1)``."""
109
+ return _arrays.kde2d_grid(xs, ys, h, x0, x1, nx, y0, y1, ny)
110
+
111
+
112
+ def argsort(values: Any, descending: bool = False) -> Any:
113
+ """Indices that sort ``values`` (stable; NaN first ascending, last descending)."""
114
+ return _arrays.argsort(values, descending=descending)