ggplot2-python 4.0.2.9000__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 (54) hide show
  1. ggplot2_py/__init__.py +852 -0
  2. ggplot2_py/_compat.py +475 -0
  3. ggplot2_py/_plugins.py +129 -0
  4. ggplot2_py/_utils.py +544 -0
  5. ggplot2_py/aes.py +586 -0
  6. ggplot2_py/annotation.py +540 -0
  7. ggplot2_py/coord.py +2108 -0
  8. ggplot2_py/coords/__init__.py +49 -0
  9. ggplot2_py/datasets.py +265 -0
  10. ggplot2_py/draw_key.py +454 -0
  11. ggplot2_py/facet.py +1456 -0
  12. ggplot2_py/fortify.py +95 -0
  13. ggplot2_py/geom.py +4516 -0
  14. ggplot2_py/geoms/__init__.py +12 -0
  15. ggplot2_py/ggproto.py +279 -0
  16. ggplot2_py/guide.py +2925 -0
  17. ggplot2_py/guide_axis.py +615 -0
  18. ggplot2_py/guide_colourbar.py +657 -0
  19. ggplot2_py/guide_legend.py +1061 -0
  20. ggplot2_py/guides/__init__.py +8 -0
  21. ggplot2_py/labeller.py +296 -0
  22. ggplot2_py/labels.py +309 -0
  23. ggplot2_py/layer.py +954 -0
  24. ggplot2_py/layout.py +754 -0
  25. ggplot2_py/limits.py +314 -0
  26. ggplot2_py/plot.py +1401 -0
  27. ggplot2_py/plot_render.py +866 -0
  28. ggplot2_py/position.py +1269 -0
  29. ggplot2_py/protocols.py +171 -0
  30. ggplot2_py/py.typed +0 -0
  31. ggplot2_py/qplot.py +233 -0
  32. ggplot2_py/resources/diamonds.csv +53941 -0
  33. ggplot2_py/resources/economics.csv +575 -0
  34. ggplot2_py/resources/economics_long.csv +2871 -0
  35. ggplot2_py/resources/faithfuld.csv +5626 -0
  36. ggplot2_py/resources/luv_colours.csv +658 -0
  37. ggplot2_py/resources/midwest.csv +438 -0
  38. ggplot2_py/resources/mpg.csv +235 -0
  39. ggplot2_py/resources/msleep.csv +84 -0
  40. ggplot2_py/resources/presidential.csv +13 -0
  41. ggplot2_py/resources/seals.csv +1156 -0
  42. ggplot2_py/resources/txhousing.csv +8603 -0
  43. ggplot2_py/save.py +316 -0
  44. ggplot2_py/scale.py +2727 -0
  45. ggplot2_py/scales/__init__.py +4252 -0
  46. ggplot2_py/stat.py +6071 -0
  47. ggplot2_py/stats/__init__.py +9 -0
  48. ggplot2_py/theme.py +490 -0
  49. ggplot2_py/theme_defaults.py +1350 -0
  50. ggplot2_py/theme_elements.py +2052 -0
  51. ggplot2_python-4.0.2.9000.dist-info/METADATA +179 -0
  52. ggplot2_python-4.0.2.9000.dist-info/RECORD +54 -0
  53. ggplot2_python-4.0.2.9000.dist-info/WHEEL +4 -0
  54. ggplot2_python-4.0.2.9000.dist-info/licenses/LICENSE +3 -0
ggplot2_py/fortify.py ADDED
@@ -0,0 +1,95 @@
1
+ """
2
+ Fortify: convert model objects to DataFrames.
3
+
4
+ In R, ``fortify()`` converts model objects (lm, etc.) to data frames for
5
+ plotting. In this Python port we focus on converting common Python data
6
+ types (dicts, arrays, None) to pandas DataFrames.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import Any, Optional
12
+
13
+ import numpy as np
14
+ import pandas as pd
15
+
16
+ from ggplot2_py._compat import Waiver, is_waiver, waiver, cli_abort
17
+
18
+ __all__ = ["fortify"]
19
+
20
+
21
+ def fortify(
22
+ model: Any,
23
+ data: Optional[pd.DataFrame] = None,
24
+ **kwargs: Any,
25
+ ) -> Any:
26
+ """Convert *model* to a :class:`~pandas.DataFrame` suitable for plotting.
27
+
28
+ Parameters
29
+ ----------
30
+ model : object
31
+ The object to convert. Supported types:
32
+
33
+ * ``None`` -- returns a :class:`~ggplot2_py._compat.Waiver` sentinel.
34
+ * ``pandas.DataFrame`` -- returned as-is.
35
+ * ``dict`` -- converted via ``pd.DataFrame(model)``.
36
+ * ``numpy.ndarray`` -- converted via ``pd.DataFrame(model)``.
37
+ * ``callable`` -- returned as-is (for functional data specification).
38
+ * Any object with ``__dataframe__`` or ``to_pandas()`` methods.
39
+ data : DataFrame, optional
40
+ Original dataset (unused in the generic implementation but kept
41
+ for signature compatibility).
42
+ **kwargs
43
+ Additional keyword arguments (unused in the generic implementation).
44
+
45
+ Returns
46
+ -------
47
+ pandas.DataFrame or Waiver or callable
48
+ A DataFrame representation of *model*, a ``Waiver`` (for ``None``),
49
+ or the original callable.
50
+
51
+ Raises
52
+ ------
53
+ ValueError
54
+ If *model* cannot be coerced into a DataFrame.
55
+ """
56
+ # None -> waiver (like R's fortify.NULL)
57
+ if model is None:
58
+ return waiver()
59
+
60
+ # Already a DataFrame
61
+ if isinstance(model, pd.DataFrame):
62
+ return model
63
+
64
+ # Waiver pass-through
65
+ if is_waiver(model):
66
+ return model
67
+
68
+ # Callable (function / lambda) -- returned as-is (like R's fortify.function)
69
+ if callable(model) and not isinstance(model, (type, np.ndarray)):
70
+ return model
71
+
72
+ # dict -> DataFrame
73
+ if isinstance(model, dict):
74
+ return pd.DataFrame(model)
75
+
76
+ # numpy array -> DataFrame
77
+ if isinstance(model, np.ndarray):
78
+ return pd.DataFrame(model)
79
+
80
+ # Objects that support the pandas interchange protocol
81
+ if hasattr(model, "to_pandas"):
82
+ return model.to_pandas()
83
+
84
+ if hasattr(model, "__dataframe__"):
85
+ return pd.api.interchange.from_dataframe(model)
86
+
87
+ # Generic fallback -- try pd.DataFrame()
88
+ try:
89
+ return pd.DataFrame(model)
90
+ except Exception as exc:
91
+ cli_abort(
92
+ "`data` must be a DataFrame, or an object coercible by fortify(), "
93
+ f"not {type(model).__name__}.",
94
+ cls=TypeError,
95
+ )