plotnine 0.15.0a1__py3-none-any.whl → 0.15.0a3__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.
- plotnine/_mpl/layout_manager/_layout_items.py +85 -23
- plotnine/_mpl/layout_manager/_layout_tree.py +16 -6
- plotnine/_mpl/layout_manager/_spaces.py +5 -5
- plotnine/_mpl/patches.py +70 -34
- plotnine/_mpl/text.py +150 -63
- plotnine/_mpl/utils.py +1 -1
- plotnine/_utils/__init__.py +30 -2
- plotnine/doctools.py +1 -1
- plotnine/facets/strips.py +17 -28
- plotnine/geoms/annotation_logticks.py +7 -8
- plotnine/geoms/annotation_stripes.py +6 -6
- plotnine/geoms/geom.py +20 -8
- plotnine/geoms/geom_abline.py +3 -2
- plotnine/geoms/geom_blank.py +0 -3
- plotnine/geoms/geom_boxplot.py +4 -4
- plotnine/geoms/geom_crossbar.py +3 -3
- plotnine/geoms/geom_dotplot.py +1 -1
- plotnine/geoms/geom_errorbar.py +2 -2
- plotnine/geoms/geom_errorbarh.py +2 -2
- plotnine/geoms/geom_hline.py +3 -2
- plotnine/geoms/geom_linerange.py +2 -2
- plotnine/geoms/geom_map.py +3 -3
- plotnine/geoms/geom_path.py +10 -11
- plotnine/geoms/geom_point.py +4 -5
- plotnine/geoms/geom_pointrange.py +3 -5
- plotnine/geoms/geom_polygon.py +2 -3
- plotnine/geoms/geom_raster.py +4 -5
- plotnine/geoms/geom_rect.py +3 -4
- plotnine/geoms/geom_ribbon.py +7 -7
- plotnine/geoms/geom_rug.py +1 -1
- plotnine/geoms/geom_segment.py +2 -2
- plotnine/geoms/geom_smooth.py +3 -3
- plotnine/geoms/geom_step.py +2 -2
- plotnine/geoms/geom_text.py +2 -3
- plotnine/geoms/geom_violin.py +4 -5
- plotnine/geoms/geom_vline.py +3 -2
- plotnine/guides/guides.py +1 -1
- plotnine/helpers.py +49 -0
- plotnine/iapi.py +28 -5
- plotnine/layer.py +18 -12
- plotnine/mapping/_eval_environment.py +1 -1
- plotnine/scales/scale_color.py +46 -14
- plotnine/scales/scale_continuous.py +5 -4
- plotnine/scales/scale_datetime.py +28 -14
- plotnine/scales/scale_discrete.py +2 -2
- plotnine/scales/scale_identity.py +10 -2
- plotnine/scales/scale_xy.py +2 -2
- plotnine/stats/binning.py +4 -1
- plotnine/stats/smoothers.py +19 -19
- plotnine/stats/stat.py +15 -25
- plotnine/stats/stat_bin.py +2 -5
- plotnine/stats/stat_bin_2d.py +7 -9
- plotnine/stats/stat_bindot.py +6 -11
- plotnine/stats/stat_boxplot.py +5 -5
- plotnine/stats/stat_count.py +5 -9
- plotnine/stats/stat_density.py +6 -9
- plotnine/stats/stat_density_2d.py +12 -9
- plotnine/stats/stat_ecdf.py +6 -5
- plotnine/stats/stat_ellipse.py +5 -6
- plotnine/stats/stat_function.py +6 -8
- plotnine/stats/stat_hull.py +2 -3
- plotnine/stats/stat_identity.py +1 -2
- plotnine/stats/stat_pointdensity.py +4 -7
- plotnine/stats/stat_qq.py +45 -20
- plotnine/stats/stat_qq_line.py +15 -11
- plotnine/stats/stat_quantile.py +6 -7
- plotnine/stats/stat_sina.py +12 -14
- plotnine/stats/stat_smooth.py +7 -10
- plotnine/stats/stat_sum.py +1 -2
- plotnine/stats/stat_summary.py +6 -9
- plotnine/stats/stat_summary_bin.py +10 -13
- plotnine/stats/stat_unique.py +1 -2
- plotnine/stats/stat_ydensity.py +7 -10
- plotnine/themes/elements/__init__.py +2 -1
- plotnine/themes/elements/margin.py +64 -1
- plotnine/themes/theme_gray.py +5 -3
- plotnine/themes/theme_matplotlib.py +5 -4
- plotnine/themes/theme_seaborn.py +7 -4
- plotnine/themes/theme_void.py +11 -4
- plotnine/themes/themeable.py +2 -2
- plotnine/typing.py +2 -2
- {plotnine-0.15.0a1.dist-info → plotnine-0.15.0a3.dist-info}/METADATA +7 -4
- {plotnine-0.15.0a1.dist-info → plotnine-0.15.0a3.dist-info}/RECORD +86 -85
- {plotnine-0.15.0a1.dist-info → plotnine-0.15.0a3.dist-info}/WHEEL +1 -1
- {plotnine-0.15.0a1.dist-info → plotnine-0.15.0a3.dist-info}/licenses/LICENSE +0 -0
- {plotnine-0.15.0a1.dist-info → plotnine-0.15.0a3.dist-info}/top_level.txt +0 -0
plotnine/geoms/geom_errorbar.py
CHANGED
|
@@ -67,7 +67,7 @@ class geom_errorbar(geom):
|
|
|
67
67
|
panel_params: panel_view,
|
|
68
68
|
coord: coord,
|
|
69
69
|
ax: Axes,
|
|
70
|
-
|
|
70
|
+
params: dict[str, Any],
|
|
71
71
|
):
|
|
72
72
|
f = np.hstack
|
|
73
73
|
# create (two horizontal bars) + vertical bar
|
|
@@ -81,4 +81,4 @@ class geom_errorbar(geom):
|
|
|
81
81
|
)
|
|
82
82
|
|
|
83
83
|
copy_missing_columns(bars, data)
|
|
84
|
-
geom_segment.draw_group(bars, panel_params, coord, ax,
|
|
84
|
+
geom_segment.draw_group(bars, panel_params, coord, ax, params)
|
plotnine/geoms/geom_errorbarh.py
CHANGED
|
@@ -67,7 +67,7 @@ class geom_errorbarh(geom):
|
|
|
67
67
|
panel_params: panel_view,
|
|
68
68
|
coord: coord,
|
|
69
69
|
ax: Axes,
|
|
70
|
-
|
|
70
|
+
params: dict[str, Any],
|
|
71
71
|
):
|
|
72
72
|
f = np.hstack
|
|
73
73
|
# create (two vertical bars) + horizontal bar
|
|
@@ -81,4 +81,4 @@ class geom_errorbarh(geom):
|
|
|
81
81
|
)
|
|
82
82
|
|
|
83
83
|
copy_missing_columns(bars, data)
|
|
84
|
-
geom_segment.draw_group(bars, panel_params, coord, ax,
|
|
84
|
+
geom_segment.draw_group(bars, panel_params, coord, ax, params)
|
plotnine/geoms/geom_hline.py
CHANGED
|
@@ -80,7 +80,6 @@ class geom_hline(geom):
|
|
|
80
80
|
panel_params: panel_view,
|
|
81
81
|
coord: coord,
|
|
82
82
|
ax: Axes,
|
|
83
|
-
**params: Any,
|
|
84
83
|
):
|
|
85
84
|
"""
|
|
86
85
|
Plot all groups
|
|
@@ -94,4 +93,6 @@ class geom_hline(geom):
|
|
|
94
93
|
|
|
95
94
|
for _, gdata in data.groupby("group"):
|
|
96
95
|
gdata.reset_index(inplace=True)
|
|
97
|
-
geom_segment.draw_group(
|
|
96
|
+
geom_segment.draw_group(
|
|
97
|
+
gdata, panel_params, coord, ax, self.params
|
|
98
|
+
)
|
plotnine/geoms/geom_linerange.py
CHANGED
|
@@ -49,7 +49,7 @@ class geom_linerange(geom):
|
|
|
49
49
|
panel_params: panel_view,
|
|
50
50
|
coord: coord,
|
|
51
51
|
ax: Axes,
|
|
52
|
-
|
|
52
|
+
params: dict[str, Any],
|
|
53
53
|
):
|
|
54
54
|
data.eval(
|
|
55
55
|
"""
|
|
@@ -59,4 +59,4 @@ class geom_linerange(geom):
|
|
|
59
59
|
""",
|
|
60
60
|
inplace=True,
|
|
61
61
|
)
|
|
62
|
-
geom_segment.draw_group(data, panel_params, coord, ax,
|
|
62
|
+
geom_segment.draw_group(data, panel_params, coord, ax, params)
|
plotnine/geoms/geom_map.py
CHANGED
|
@@ -119,11 +119,11 @@ class geom_map(geom):
|
|
|
119
119
|
panel_params: panel_view,
|
|
120
120
|
coord: coord,
|
|
121
121
|
ax: Axes,
|
|
122
|
-
**params: Any,
|
|
123
122
|
):
|
|
124
123
|
if not len(data):
|
|
125
124
|
return
|
|
126
125
|
|
|
126
|
+
params = self.params
|
|
127
127
|
data.loc[data["color"].isna(), "color"] = "none"
|
|
128
128
|
data.loc[data["fill"].isna(), "fill"] = "none"
|
|
129
129
|
data["fill"] = to_rgba(data["fill"], data["alpha"])
|
|
@@ -153,7 +153,7 @@ class geom_map(geom):
|
|
|
153
153
|
for _, gdata in data.groupby("group"):
|
|
154
154
|
gdata.reset_index(inplace=True, drop=True)
|
|
155
155
|
gdata.is_copy = None
|
|
156
|
-
geom_point.draw_group(gdata, panel_params, coord, ax,
|
|
156
|
+
geom_point.draw_group(gdata, panel_params, coord, ax, params)
|
|
157
157
|
elif geom_type == "MultiPoint":
|
|
158
158
|
# Where n is the length of the dataframe (no. of multipoints),
|
|
159
159
|
# m is the number of all points in all multipoints
|
|
@@ -168,7 +168,7 @@ class geom_map(geom):
|
|
|
168
168
|
data = data.explode("points", ignore_index=True)
|
|
169
169
|
data["x"] = [p[0] for p in data["points"]]
|
|
170
170
|
data["y"] = [p[1] for p in data["points"]]
|
|
171
|
-
geom_point.draw_group(data, panel_params, coord, ax,
|
|
171
|
+
geom_point.draw_group(data, panel_params, coord, ax, params)
|
|
172
172
|
elif geom_type in ("LineString", "MultiLineString"):
|
|
173
173
|
from matplotlib.collections import LineCollection
|
|
174
174
|
|
plotnine/geoms/geom_path.py
CHANGED
|
@@ -107,7 +107,6 @@ class geom_path(geom):
|
|
|
107
107
|
panel_params: panel_view,
|
|
108
108
|
coord: coord,
|
|
109
109
|
ax: Axes,
|
|
110
|
-
**params: Any,
|
|
111
110
|
):
|
|
112
111
|
if not any(data["group"].duplicated()):
|
|
113
112
|
warn(
|
|
@@ -138,14 +137,14 @@ class geom_path(geom):
|
|
|
138
137
|
ngroup = len(np.unique(data["group"].to_numpy()))
|
|
139
138
|
|
|
140
139
|
constant = num_unique_rows == ngroup
|
|
141
|
-
params["constant"] = constant
|
|
140
|
+
self.params["constant"] = constant
|
|
142
141
|
|
|
143
142
|
if not constant:
|
|
144
|
-
self.draw_group(data, panel_params, coord, ax,
|
|
143
|
+
self.draw_group(data, panel_params, coord, ax, self.params)
|
|
145
144
|
else:
|
|
146
145
|
for _, gdata in data.groupby("group"):
|
|
147
146
|
gdata.reset_index(inplace=True, drop=True)
|
|
148
|
-
self.draw_group(gdata, panel_params, coord, ax,
|
|
147
|
+
self.draw_group(gdata, panel_params, coord, ax, self.params)
|
|
149
148
|
|
|
150
149
|
@staticmethod
|
|
151
150
|
def draw_group(
|
|
@@ -153,7 +152,7 @@ class geom_path(geom):
|
|
|
153
152
|
panel_params: panel_view,
|
|
154
153
|
coord: coord,
|
|
155
154
|
ax: Axes,
|
|
156
|
-
|
|
155
|
+
params: dict[str, Any],
|
|
157
156
|
):
|
|
158
157
|
data = coord.transform(data, panel_params, munch=True)
|
|
159
158
|
data["linewidth"] = data["size"] * SIZE_FACTOR
|
|
@@ -164,13 +163,13 @@ class geom_path(geom):
|
|
|
164
163
|
constant = len(np.unique(data["group"].to_numpy())) == 1
|
|
165
164
|
|
|
166
165
|
if not constant:
|
|
167
|
-
_draw_segments(data, ax,
|
|
166
|
+
_draw_segments(data, ax, params)
|
|
168
167
|
else:
|
|
169
|
-
_draw_lines(data, ax,
|
|
168
|
+
_draw_lines(data, ax, params)
|
|
170
169
|
|
|
171
170
|
if "arrow" in params and params["arrow"]:
|
|
172
171
|
params["arrow"].draw(
|
|
173
|
-
data, panel_params, coord, ax, constant=constant
|
|
172
|
+
data, panel_params, coord, ax, params, constant=constant
|
|
174
173
|
)
|
|
175
174
|
|
|
176
175
|
@staticmethod
|
|
@@ -264,8 +263,8 @@ class arrow:
|
|
|
264
263
|
panel_params: panel_view,
|
|
265
264
|
coord: coord,
|
|
266
265
|
ax: Axes,
|
|
266
|
+
params: dict[str, Any],
|
|
267
267
|
constant: bool = True,
|
|
268
|
-
**params: Any,
|
|
269
268
|
):
|
|
270
269
|
"""
|
|
271
270
|
Draw arrows at the end(s) of the lines
|
|
@@ -454,7 +453,7 @@ class arrow:
|
|
|
454
453
|
return paths
|
|
455
454
|
|
|
456
455
|
|
|
457
|
-
def _draw_segments(data: pd.DataFrame, ax: Axes,
|
|
456
|
+
def _draw_segments(data: pd.DataFrame, ax: Axes, params: dict[str, Any]):
|
|
458
457
|
"""
|
|
459
458
|
Draw independent line segments between all the
|
|
460
459
|
points
|
|
@@ -493,7 +492,7 @@ def _draw_segments(data: pd.DataFrame, ax: Axes, **params: Any):
|
|
|
493
492
|
ax.add_collection(coll)
|
|
494
493
|
|
|
495
494
|
|
|
496
|
-
def _draw_lines(data: pd.DataFrame, ax: Axes,
|
|
495
|
+
def _draw_lines(data: pd.DataFrame, ax: Axes, params: dict[str, Any]):
|
|
497
496
|
"""
|
|
498
497
|
Draw a path with the same characteristics from the
|
|
499
498
|
first point to the last point
|
plotnine/geoms/geom_point.py
CHANGED
|
@@ -55,12 +55,11 @@ class geom_point(geom):
|
|
|
55
55
|
panel_params: panel_view,
|
|
56
56
|
coord: coord,
|
|
57
57
|
ax: Axes,
|
|
58
|
-
**params: Any,
|
|
59
58
|
):
|
|
60
59
|
"""
|
|
61
60
|
Plot all groups
|
|
62
61
|
"""
|
|
63
|
-
self.draw_group(data, panel_params, coord, ax,
|
|
62
|
+
self.draw_group(data, panel_params, coord, ax, self.params)
|
|
64
63
|
|
|
65
64
|
@staticmethod
|
|
66
65
|
def draw_group(
|
|
@@ -68,13 +67,13 @@ class geom_point(geom):
|
|
|
68
67
|
panel_params: panel_view,
|
|
69
68
|
coord: coord,
|
|
70
69
|
ax: Axes,
|
|
71
|
-
|
|
70
|
+
params: dict[str, Any],
|
|
72
71
|
):
|
|
73
72
|
data = coord.transform(data, panel_params)
|
|
74
73
|
units = "shape"
|
|
75
74
|
for _, udata in data.groupby(units, dropna=False):
|
|
76
75
|
udata.reset_index(inplace=True, drop=True)
|
|
77
|
-
geom_point.draw_unit(udata, panel_params, coord, ax,
|
|
76
|
+
geom_point.draw_unit(udata, panel_params, coord, ax, params)
|
|
78
77
|
|
|
79
78
|
@staticmethod
|
|
80
79
|
def draw_unit(
|
|
@@ -82,7 +81,7 @@ class geom_point(geom):
|
|
|
82
81
|
panel_params: panel_view,
|
|
83
82
|
coord: coord,
|
|
84
83
|
ax: Axes,
|
|
85
|
-
|
|
84
|
+
params: dict[str, Any],
|
|
86
85
|
):
|
|
87
86
|
# Our size is in 'points' while scatter wants
|
|
88
87
|
# 'points^2'. The stroke is outside. And pi
|
|
@@ -58,14 +58,12 @@ class geom_pointrange(geom):
|
|
|
58
58
|
panel_params: panel_view,
|
|
59
59
|
coord: coord,
|
|
60
60
|
ax: Axes,
|
|
61
|
-
|
|
61
|
+
params: dict[str, Any],
|
|
62
62
|
):
|
|
63
|
-
geom_linerange.draw_group(
|
|
64
|
-
data.copy(), panel_params, coord, ax, **params
|
|
65
|
-
)
|
|
63
|
+
geom_linerange.draw_group(data.copy(), panel_params, coord, ax, params)
|
|
66
64
|
data["size"] = data["size"] * params["fatten"]
|
|
67
65
|
data["stroke"] = geom_point.DEFAULT_AES["stroke"]
|
|
68
|
-
geom_point.draw_group(data, panel_params, coord, ax,
|
|
66
|
+
geom_point.draw_group(data, panel_params, coord, ax, params)
|
|
69
67
|
|
|
70
68
|
@staticmethod
|
|
71
69
|
def draw_legend(
|
plotnine/geoms/geom_polygon.py
CHANGED
|
@@ -62,12 +62,11 @@ class geom_polygon(geom):
|
|
|
62
62
|
panel_params: panel_view,
|
|
63
63
|
coord: coord,
|
|
64
64
|
ax: Axes,
|
|
65
|
-
**params: Any,
|
|
66
65
|
):
|
|
67
66
|
"""
|
|
68
67
|
Plot all groups
|
|
69
68
|
"""
|
|
70
|
-
self.draw_group(data, panel_params, coord, ax,
|
|
69
|
+
self.draw_group(data, panel_params, coord, ax, self.params)
|
|
71
70
|
|
|
72
71
|
@staticmethod
|
|
73
72
|
def draw_group(
|
|
@@ -75,7 +74,7 @@ class geom_polygon(geom):
|
|
|
75
74
|
panel_params: panel_view,
|
|
76
75
|
coord: coord,
|
|
77
76
|
ax: Axes,
|
|
78
|
-
|
|
77
|
+
params: dict[str, Any],
|
|
79
78
|
):
|
|
80
79
|
from matplotlib.collections import PolyCollection
|
|
81
80
|
|
plotnine/geoms/geom_raster.py
CHANGED
|
@@ -155,7 +155,6 @@ class geom_raster(geom):
|
|
|
155
155
|
panel_params: panel_view,
|
|
156
156
|
coord: coord,
|
|
157
157
|
ax: Axes,
|
|
158
|
-
**params: Any,
|
|
159
158
|
):
|
|
160
159
|
"""
|
|
161
160
|
Plot all groups
|
|
@@ -194,7 +193,7 @@ class geom_raster(geom):
|
|
|
194
193
|
im = AxesImage(
|
|
195
194
|
ax,
|
|
196
195
|
data=X,
|
|
197
|
-
interpolation=params["interpolation"],
|
|
196
|
+
interpolation=self.params["interpolation"],
|
|
198
197
|
origin="upper",
|
|
199
198
|
extent=(
|
|
200
199
|
data["xmin"].min(),
|
|
@@ -202,8 +201,8 @@ class geom_raster(geom):
|
|
|
202
201
|
data["ymin"].min(),
|
|
203
202
|
data["ymax"].max(),
|
|
204
203
|
),
|
|
205
|
-
rasterized=params["raster"],
|
|
206
|
-
filterrad=params["filterrad"],
|
|
207
|
-
zorder=params["zorder"],
|
|
204
|
+
rasterized=self.params["raster"],
|
|
205
|
+
filterrad=self.params["filterrad"],
|
|
206
|
+
zorder=self.params["zorder"],
|
|
208
207
|
)
|
|
209
208
|
ax.add_image(im)
|
plotnine/geoms/geom_rect.py
CHANGED
|
@@ -52,7 +52,6 @@ class geom_rect(geom):
|
|
|
52
52
|
panel_params: panel_view,
|
|
53
53
|
coord: coord,
|
|
54
54
|
ax: Axes,
|
|
55
|
-
**params: Any,
|
|
56
55
|
):
|
|
57
56
|
"""
|
|
58
57
|
Plot all groups
|
|
@@ -62,10 +61,10 @@ class geom_rect(geom):
|
|
|
62
61
|
for _, gdata in data.groupby("group"):
|
|
63
62
|
gdata.reset_index(inplace=True, drop=True)
|
|
64
63
|
geom_polygon.draw_group(
|
|
65
|
-
gdata, panel_params, coord, ax,
|
|
64
|
+
gdata, panel_params, coord, ax, self.params
|
|
66
65
|
)
|
|
67
66
|
else:
|
|
68
|
-
self.draw_group(data, panel_params, coord, ax,
|
|
67
|
+
self.draw_group(data, panel_params, coord, ax, self.params)
|
|
69
68
|
|
|
70
69
|
@staticmethod
|
|
71
70
|
def draw_group(
|
|
@@ -73,7 +72,7 @@ class geom_rect(geom):
|
|
|
73
72
|
panel_params: panel_view,
|
|
74
73
|
coord: coord,
|
|
75
74
|
ax: Axes,
|
|
76
|
-
|
|
75
|
+
params: dict[str, Any],
|
|
77
76
|
):
|
|
78
77
|
from matplotlib.collections import PolyCollection
|
|
79
78
|
|
plotnine/geoms/geom_ribbon.py
CHANGED
|
@@ -94,7 +94,7 @@ class geom_ribbon(geom):
|
|
|
94
94
|
panel_params: panel_view,
|
|
95
95
|
coord: coord,
|
|
96
96
|
ax: Axes,
|
|
97
|
-
|
|
97
|
+
params: dict[str, Any],
|
|
98
98
|
):
|
|
99
99
|
_x = "y" if isinstance(coord, coord_flip) else "x"
|
|
100
100
|
data = coord.transform(data, panel_params, munch=True)
|
|
@@ -107,7 +107,7 @@ class geom_ribbon(geom):
|
|
|
107
107
|
|
|
108
108
|
for _, udata in data.groupby(units, dropna=False):
|
|
109
109
|
udata.reset_index(inplace=True, drop=True)
|
|
110
|
-
geom_ribbon.draw_unit(udata, panel_params, coord, ax,
|
|
110
|
+
geom_ribbon.draw_unit(udata, panel_params, coord, ax, params)
|
|
111
111
|
|
|
112
112
|
@staticmethod
|
|
113
113
|
def draw_unit(
|
|
@@ -115,7 +115,7 @@ class geom_ribbon(geom):
|
|
|
115
115
|
panel_params: panel_view,
|
|
116
116
|
coord: coord,
|
|
117
117
|
ax: Axes,
|
|
118
|
-
|
|
118
|
+
params: dict[str, Any],
|
|
119
119
|
):
|
|
120
120
|
linewidth = data["size"].iloc[0] * SIZE_FACTOR
|
|
121
121
|
fill = to_rgba(data["fill"], data["alpha"])
|
|
@@ -159,7 +159,7 @@ class geom_ribbon(geom):
|
|
|
159
159
|
|
|
160
160
|
# Alpha does not affect the outlines
|
|
161
161
|
data["alpha"] = 1
|
|
162
|
-
geom_ribbon._draw_outline(data, panel_params, coord, ax,
|
|
162
|
+
geom_ribbon._draw_outline(data, panel_params, coord, ax, params)
|
|
163
163
|
|
|
164
164
|
@staticmethod
|
|
165
165
|
def _draw_outline(
|
|
@@ -167,7 +167,7 @@ class geom_ribbon(geom):
|
|
|
167
167
|
panel_params: panel_view,
|
|
168
168
|
coord: coord,
|
|
169
169
|
ax: Axes,
|
|
170
|
-
|
|
170
|
+
params: dict[str, Any],
|
|
171
171
|
):
|
|
172
172
|
outline_type = params["outline_type"]
|
|
173
173
|
|
|
@@ -185,7 +185,7 @@ class geom_ribbon(geom):
|
|
|
185
185
|
panel_params,
|
|
186
186
|
coord,
|
|
187
187
|
ax,
|
|
188
|
-
|
|
188
|
+
params,
|
|
189
189
|
)
|
|
190
190
|
|
|
191
191
|
if outline_type in ("upper", "both"):
|
|
@@ -194,5 +194,5 @@ class geom_ribbon(geom):
|
|
|
194
194
|
panel_params,
|
|
195
195
|
coord,
|
|
196
196
|
ax,
|
|
197
|
-
|
|
197
|
+
params,
|
|
198
198
|
)
|
plotnine/geoms/geom_rug.py
CHANGED
plotnine/geoms/geom_segment.py
CHANGED
|
@@ -64,7 +64,7 @@ class geom_segment(geom):
|
|
|
64
64
|
panel_params: panel_view,
|
|
65
65
|
coord: coord,
|
|
66
66
|
ax: Axes,
|
|
67
|
-
|
|
67
|
+
params: dict[str, Any],
|
|
68
68
|
):
|
|
69
69
|
from matplotlib.collections import LineCollection
|
|
70
70
|
|
|
@@ -100,5 +100,5 @@ class geom_segment(geom):
|
|
|
100
100
|
adata[param] = np.hstack([data[param], data[param]])
|
|
101
101
|
|
|
102
102
|
params["arrow"].draw(
|
|
103
|
-
adata, panel_params, coord, ax, constant=False
|
|
103
|
+
adata, panel_params, coord, ax, params, constant=False
|
|
104
104
|
)
|
plotnine/geoms/geom_smooth.py
CHANGED
|
@@ -78,7 +78,7 @@ class geom_smooth(geom):
|
|
|
78
78
|
panel_params: panel_view,
|
|
79
79
|
coord: coord,
|
|
80
80
|
ax: Axes,
|
|
81
|
-
|
|
81
|
+
params: dict[str, Any],
|
|
82
82
|
):
|
|
83
83
|
has_ribbon = "ymin" in data and "ymax" in data
|
|
84
84
|
if has_ribbon:
|
|
@@ -86,10 +86,10 @@ class geom_smooth(geom):
|
|
|
86
86
|
data2["color"] = "none"
|
|
87
87
|
params2 = params.copy()
|
|
88
88
|
params2["outline_type"] = "full"
|
|
89
|
-
geom_ribbon.draw_group(data2, panel_params, coord, ax,
|
|
89
|
+
geom_ribbon.draw_group(data2, panel_params, coord, ax, params2)
|
|
90
90
|
|
|
91
91
|
data["alpha"] = 1
|
|
92
|
-
geom_line.draw_group(data, panel_params, coord, ax,
|
|
92
|
+
geom_line.draw_group(data, panel_params, coord, ax, params)
|
|
93
93
|
|
|
94
94
|
@staticmethod
|
|
95
95
|
def draw_legend(
|
plotnine/geoms/geom_step.py
CHANGED
|
@@ -54,7 +54,7 @@ class geom_step(geom_path):
|
|
|
54
54
|
panel_params: panel_view,
|
|
55
55
|
coord: coord,
|
|
56
56
|
ax: Axes,
|
|
57
|
-
|
|
57
|
+
params: dict[str, Any],
|
|
58
58
|
):
|
|
59
59
|
direction = params["direction"]
|
|
60
60
|
n = len(data)
|
|
@@ -84,4 +84,4 @@ class geom_step(geom_path):
|
|
|
84
84
|
|
|
85
85
|
path_data = pd.DataFrame({"x": new_x, "y": new_y})
|
|
86
86
|
copy_missing_columns(path_data, data)
|
|
87
|
-
geom_path.draw_group(path_data, panel_params, coord, ax,
|
|
87
|
+
geom_path.draw_group(path_data, panel_params, coord, ax, params)
|
plotnine/geoms/geom_text.py
CHANGED
|
@@ -214,9 +214,8 @@ class geom_text(geom):
|
|
|
214
214
|
panel_params: panel_view,
|
|
215
215
|
coord: coord,
|
|
216
216
|
ax: Axes,
|
|
217
|
-
**params: Any,
|
|
218
217
|
):
|
|
219
|
-
super().draw_panel(data, panel_params, coord, ax
|
|
218
|
+
super().draw_panel(data, panel_params, coord, ax)
|
|
220
219
|
|
|
221
220
|
@staticmethod
|
|
222
221
|
def draw_group(
|
|
@@ -224,7 +223,7 @@ class geom_text(geom):
|
|
|
224
223
|
panel_params: panel_view,
|
|
225
224
|
coord: coord,
|
|
226
225
|
ax: Axes,
|
|
227
|
-
|
|
226
|
+
params: dict[str, Any],
|
|
228
227
|
):
|
|
229
228
|
data = coord.transform(data, panel_params)
|
|
230
229
|
zorder = params["zorder"]
|
plotnine/geoms/geom_violin.py
CHANGED
|
@@ -113,8 +113,8 @@ class geom_violin(geom):
|
|
|
113
113
|
panel_params: panel_view,
|
|
114
114
|
coord: coord,
|
|
115
115
|
ax: Axes,
|
|
116
|
-
**params: Any,
|
|
117
116
|
):
|
|
117
|
+
params = self.params.copy()
|
|
118
118
|
quantiles = params.pop("draw_quantiles")
|
|
119
119
|
style = params.pop("style")
|
|
120
120
|
zorder = params.pop("zorder")
|
|
@@ -125,6 +125,7 @@ class geom_violin(geom):
|
|
|
125
125
|
# in the range [zorder, zorder + 1) to stay within the layer.
|
|
126
126
|
group = cast("int", group)
|
|
127
127
|
group_zorder = zorder + 0.9 / group
|
|
128
|
+
params["zorder"] = group_zorder
|
|
128
129
|
|
|
129
130
|
# Find the points for the line to go all the way around
|
|
130
131
|
df["xminv"] = df["x"] - df["violinwidth"] * (df["x"] - df["xmin"])
|
|
@@ -167,8 +168,7 @@ class geom_violin(geom):
|
|
|
167
168
|
panel_params,
|
|
168
169
|
coord,
|
|
169
170
|
ax,
|
|
170
|
-
|
|
171
|
-
**params,
|
|
171
|
+
params,
|
|
172
172
|
)
|
|
173
173
|
|
|
174
174
|
if quantiles is not None:
|
|
@@ -190,8 +190,7 @@ class geom_violin(geom):
|
|
|
190
190
|
panel_params,
|
|
191
191
|
coord,
|
|
192
192
|
ax,
|
|
193
|
-
|
|
194
|
-
**params,
|
|
193
|
+
params,
|
|
195
194
|
)
|
|
196
195
|
|
|
197
196
|
|
plotnine/geoms/geom_vline.py
CHANGED
|
@@ -80,7 +80,6 @@ class geom_vline(geom):
|
|
|
80
80
|
panel_params: panel_view,
|
|
81
81
|
coord: coord,
|
|
82
82
|
ax: Axes,
|
|
83
|
-
**params: Any,
|
|
84
83
|
):
|
|
85
84
|
"""
|
|
86
85
|
Plot all groups
|
|
@@ -94,7 +93,9 @@ class geom_vline(geom):
|
|
|
94
93
|
|
|
95
94
|
for _, gdata in data.groupby("group"):
|
|
96
95
|
gdata.reset_index(inplace=True)
|
|
97
|
-
geom_segment.draw_group(
|
|
96
|
+
geom_segment.draw_group(
|
|
97
|
+
gdata, panel_params, coord, ax, self.params
|
|
98
|
+
)
|
|
98
99
|
|
|
99
100
|
@staticmethod
|
|
100
101
|
def draw_legend(
|
plotnine/guides/guides.py
CHANGED
|
@@ -369,7 +369,7 @@ class guides:
|
|
|
369
369
|
# place the guides according to the guide.order
|
|
370
370
|
default = max(g.order for g in gdefs) + 1
|
|
371
371
|
orders = [default if g.order == 0 else g.order for g in gdefs]
|
|
372
|
-
idx
|
|
372
|
+
idx = cast("Sequence[int]", np.argsort(orders))
|
|
373
373
|
gdefs = [gdefs[i] for i in idx]
|
|
374
374
|
|
|
375
375
|
# Draw each guide into a box
|
plotnine/helpers.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from typing import Sequence
|
|
8
|
+
|
|
9
|
+
from plotnine import ggplot
|
|
10
|
+
|
|
11
|
+
__all__ = ("get_aesthetic_limits",)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_aesthetic_limits(
|
|
15
|
+
plot: ggplot,
|
|
16
|
+
ae: str,
|
|
17
|
+
) -> (
|
|
18
|
+
tuple[float, float]
|
|
19
|
+
| Sequence[str]
|
|
20
|
+
| list[tuple[float]]
|
|
21
|
+
| list[Sequence[str]]
|
|
22
|
+
):
|
|
23
|
+
"""
|
|
24
|
+
Get the limits of an aesthetic
|
|
25
|
+
|
|
26
|
+
These are the limits before they are expanded.
|
|
27
|
+
|
|
28
|
+
Parameters
|
|
29
|
+
----------
|
|
30
|
+
plot :
|
|
31
|
+
ggplot object
|
|
32
|
+
|
|
33
|
+
ae :
|
|
34
|
+
Name of aesthetic
|
|
35
|
+
|
|
36
|
+
Returns
|
|
37
|
+
-------
|
|
38
|
+
out :
|
|
39
|
+
The limits of the aesthetic. If the plot is facetted, (has many
|
|
40
|
+
panels), it is a sequence of limits, one for each panel.
|
|
41
|
+
"""
|
|
42
|
+
plot = deepcopy(plot)
|
|
43
|
+
plot._build()
|
|
44
|
+
limits = [
|
|
45
|
+
getattr(panel, ae).limits
|
|
46
|
+
for panel in plot._build_objs.layout.panel_params
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
return limits[0] if len(limits) == 1 else limits
|
plotnine/iapi.py
CHANGED
|
@@ -10,6 +10,7 @@ from __future__ import annotations
|
|
|
10
10
|
import itertools
|
|
11
11
|
from copy import copy
|
|
12
12
|
from dataclasses import dataclass, field, fields
|
|
13
|
+
from functools import cached_property
|
|
13
14
|
from typing import TYPE_CHECKING
|
|
14
15
|
|
|
15
16
|
if TYPE_CHECKING:
|
|
@@ -19,6 +20,7 @@ if TYPE_CHECKING:
|
|
|
19
20
|
from matplotlib.figure import Figure
|
|
20
21
|
|
|
21
22
|
from plotnine.scales.scale import scale
|
|
23
|
+
from plotnine.themes.elements.margin import margin
|
|
22
24
|
from plotnine.typing import (
|
|
23
25
|
CoordRange,
|
|
24
26
|
FloatArrayLike,
|
|
@@ -231,13 +233,27 @@ class strip_draw_info:
|
|
|
231
233
|
Information required to draw strips
|
|
232
234
|
"""
|
|
233
235
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
+
bg_x: float
|
|
237
|
+
"""Left of the strip background in transAxes"""
|
|
238
|
+
|
|
239
|
+
bg_y: float
|
|
240
|
+
"""Bottom of the strip background in transAxes"""
|
|
241
|
+
|
|
236
242
|
ha: HorizontalJustification | float
|
|
243
|
+
"""Horizontal justification of strip text within the background"""
|
|
244
|
+
|
|
237
245
|
va: VerticalJustification | float
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
246
|
+
"""Vertical justification of strip text within the background"""
|
|
247
|
+
|
|
248
|
+
bg_width: float
|
|
249
|
+
"""Width of the strip background in transAxes"""
|
|
250
|
+
|
|
251
|
+
bg_height: float
|
|
252
|
+
"""Height of the strip background in transAxes"""
|
|
253
|
+
|
|
254
|
+
margin: margin
|
|
255
|
+
"""Strip text margin with the units in lines"""
|
|
256
|
+
|
|
241
257
|
strip_align: float
|
|
242
258
|
position: StripPosition
|
|
243
259
|
label: str
|
|
@@ -245,6 +261,13 @@ class strip_draw_info:
|
|
|
245
261
|
rotation: float
|
|
246
262
|
layout: layout_details
|
|
247
263
|
|
|
264
|
+
@cached_property
|
|
265
|
+
def is_oneline(self) -> bool:
|
|
266
|
+
"""
|
|
267
|
+
Whether the strip text is a single line
|
|
268
|
+
"""
|
|
269
|
+
return len(self.label.split("\n")) == 1
|
|
270
|
+
|
|
248
271
|
|
|
249
272
|
@dataclass
|
|
250
273
|
class strip_label_details:
|