plotnine 0.15.0a2__py3-none-any.whl → 0.15.0a4__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 (70) hide show
  1. plotnine/_mpl/layout_manager/_layout_tree.py +16 -6
  2. plotnine/_utils/__init__.py +7 -103
  3. plotnine/doctools.py +3 -3
  4. plotnine/geoms/annotate.py +10 -10
  5. plotnine/geoms/annotation_logticks.py +5 -8
  6. plotnine/geoms/annotation_stripes.py +4 -6
  7. plotnine/geoms/geom.py +41 -20
  8. plotnine/geoms/geom_abline.py +3 -2
  9. plotnine/geoms/geom_blank.py +0 -3
  10. plotnine/geoms/geom_boxplot.py +4 -4
  11. plotnine/geoms/geom_crossbar.py +3 -3
  12. plotnine/geoms/geom_dotplot.py +1 -1
  13. plotnine/geoms/geom_errorbar.py +2 -2
  14. plotnine/geoms/geom_errorbarh.py +2 -2
  15. plotnine/geoms/geom_hline.py +3 -2
  16. plotnine/geoms/geom_linerange.py +2 -2
  17. plotnine/geoms/geom_map.py +3 -3
  18. plotnine/geoms/geom_path.py +10 -11
  19. plotnine/geoms/geom_point.py +4 -5
  20. plotnine/geoms/geom_pointrange.py +3 -5
  21. plotnine/geoms/geom_polygon.py +2 -3
  22. plotnine/geoms/geom_raster.py +4 -5
  23. plotnine/geoms/geom_rect.py +3 -4
  24. plotnine/geoms/geom_ribbon.py +7 -7
  25. plotnine/geoms/geom_rug.py +1 -1
  26. plotnine/geoms/geom_segment.py +2 -2
  27. plotnine/geoms/geom_smooth.py +3 -3
  28. plotnine/geoms/geom_step.py +2 -2
  29. plotnine/geoms/geom_text.py +2 -3
  30. plotnine/geoms/geom_violin.py +4 -5
  31. plotnine/geoms/geom_vline.py +3 -2
  32. plotnine/guides/guides.py +1 -1
  33. plotnine/layer.py +20 -12
  34. plotnine/mapping/_eval_environment.py +1 -1
  35. plotnine/mapping/aes.py +75 -45
  36. plotnine/scales/scale_color.py +46 -14
  37. plotnine/scales/scale_continuous.py +4 -3
  38. plotnine/scales/scale_datetime.py +28 -14
  39. plotnine/scales/scale_discrete.py +1 -1
  40. plotnine/scales/scale_xy.py +2 -2
  41. plotnine/stats/smoothers.py +19 -19
  42. plotnine/stats/stat.py +15 -25
  43. plotnine/stats/stat_bin.py +2 -5
  44. plotnine/stats/stat_bin_2d.py +7 -9
  45. plotnine/stats/stat_bindot.py +5 -8
  46. plotnine/stats/stat_boxplot.py +5 -5
  47. plotnine/stats/stat_count.py +5 -9
  48. plotnine/stats/stat_density.py +5 -8
  49. plotnine/stats/stat_density_2d.py +11 -8
  50. plotnine/stats/stat_ecdf.py +6 -5
  51. plotnine/stats/stat_ellipse.py +5 -6
  52. plotnine/stats/stat_function.py +6 -8
  53. plotnine/stats/stat_hull.py +2 -3
  54. plotnine/stats/stat_identity.py +1 -2
  55. plotnine/stats/stat_pointdensity.py +4 -7
  56. plotnine/stats/stat_qq.py +45 -20
  57. plotnine/stats/stat_qq_line.py +15 -11
  58. plotnine/stats/stat_quantile.py +6 -7
  59. plotnine/stats/stat_sina.py +12 -14
  60. plotnine/stats/stat_smooth.py +7 -10
  61. plotnine/stats/stat_sum.py +1 -2
  62. plotnine/stats/stat_summary.py +6 -9
  63. plotnine/stats/stat_summary_bin.py +10 -13
  64. plotnine/stats/stat_unique.py +1 -2
  65. plotnine/stats/stat_ydensity.py +7 -10
  66. {plotnine-0.15.0a2.dist-info → plotnine-0.15.0a4.dist-info}/METADATA +4 -4
  67. {plotnine-0.15.0a2.dist-info → plotnine-0.15.0a4.dist-info}/RECORD +70 -70
  68. {plotnine-0.15.0a2.dist-info → plotnine-0.15.0a4.dist-info}/WHEEL +1 -1
  69. {plotnine-0.15.0a2.dist-info → plotnine-0.15.0a4.dist-info}/licenses/LICENSE +0 -0
  70. {plotnine-0.15.0a2.dist-info → plotnine-0.15.0a4.dist-info}/top_level.txt +0 -0
@@ -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, **params)
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, **params)
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
- **params: Any,
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, **params)
166
+ _draw_segments(data, ax, params)
168
167
  else:
169
- _draw_lines(data, ax, **params)
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, **params
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, **params: Any):
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, **params: Any):
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
@@ -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, **params)
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
- **params: Any,
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, **params)
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
- **params: Any,
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
- **params: Any,
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, **params)
66
+ geom_point.draw_group(data, panel_params, coord, ax, params)
69
67
 
70
68
  @staticmethod
71
69
  def draw_legend(
@@ -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, **params)
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
- **params: Any,
77
+ params: dict[str, Any],
79
78
  ):
80
79
  from matplotlib.collections import PolyCollection
81
80
 
@@ -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)
@@ -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, **params
64
+ gdata, panel_params, coord, ax, self.params
66
65
  )
67
66
  else:
68
- self.draw_group(data, panel_params, coord, ax, **params)
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
- **params: Any,
75
+ params: dict[str, Any],
77
76
  ):
78
77
  from matplotlib.collections import PolyCollection
79
78
 
@@ -94,7 +94,7 @@ class geom_ribbon(geom):
94
94
  panel_params: panel_view,
95
95
  coord: coord,
96
96
  ax: Axes,
97
- **params: Any,
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, **params)
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
- **params: Any,
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, **params)
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
- **params: Any,
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
- **params,
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
- **params,
197
+ params,
198
198
  )
@@ -60,7 +60,7 @@ class geom_rug(geom):
60
60
  panel_params: panel_view,
61
61
  coord: coord,
62
62
  ax: Axes,
63
- **params: Any,
63
+ params: dict[str, Any],
64
64
  ):
65
65
  from matplotlib.collections import LineCollection
66
66
 
@@ -64,7 +64,7 @@ class geom_segment(geom):
64
64
  panel_params: panel_view,
65
65
  coord: coord,
66
66
  ax: Axes,
67
- **params: Any,
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, **params
103
+ adata, panel_params, coord, ax, params, constant=False
104
104
  )
@@ -78,7 +78,7 @@ class geom_smooth(geom):
78
78
  panel_params: panel_view,
79
79
  coord: coord,
80
80
  ax: Axes,
81
- **params: Any,
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, **params2)
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, **params)
92
+ geom_line.draw_group(data, panel_params, coord, ax, params)
93
93
 
94
94
  @staticmethod
95
95
  def draw_legend(
@@ -54,7 +54,7 @@ class geom_step(geom_path):
54
54
  panel_params: panel_view,
55
55
  coord: coord,
56
56
  ax: Axes,
57
- **params: Any,
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, **params)
87
+ geom_path.draw_group(path_data, panel_params, coord, ax, params)
@@ -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, **params)
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
- **params: Any,
226
+ params: dict[str, Any],
228
227
  ):
229
228
  data = coord.transform(data, panel_params)
230
229
  zorder = params["zorder"]
@@ -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
- zorder=group_zorder,
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
- zorder=group_zorder,
194
- **params,
193
+ params,
195
194
  )
196
195
 
197
196
 
@@ -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(gdata, panel_params, coord, ax, **params)
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: list[int] = list(np.argsort(orders))
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/layer.py CHANGED
@@ -163,6 +163,7 @@ class layer:
163
163
  self._make_layer_data(plot.data)
164
164
  self._make_layer_mapping(plot.mapping)
165
165
  self._make_layer_environments(plot.environment)
166
+ self._share_layer_params()
166
167
 
167
168
  def _make_layer_data(self, plot_data: DataLike | None):
168
169
  """
@@ -250,6 +251,14 @@ class layer:
250
251
  self.geom.environment = plot_environment
251
252
  self.stat.environment = plot_environment
252
253
 
254
+ def _share_layer_params(self):
255
+ """
256
+ Pass necessary layer parameters to the geom
257
+ """
258
+ self.geom.params["zorder"] = self.zorder
259
+ self.geom.params["raster"] = self.raster
260
+ self.geom.params["inherit_aes"] = self.inherit_aes
261
+
253
262
  def compute_aesthetics(self, plot: ggplot):
254
263
  """
255
264
  Return a dataframe where the columns match the aesthetic mappings
@@ -278,10 +287,10 @@ class layer:
278
287
  if not len(data):
279
288
  return
280
289
 
281
- params = self.stat.setup_params(data)
290
+ self.stat.setup_params(data)
282
291
  data = self.stat.use_defaults(data)
283
292
  data = self.stat.setup_data(data)
284
- data = self.stat.compute_layer(data, params, layout)
293
+ data = self.stat.compute_layer(data, layout)
285
294
  self.data = data
286
295
 
287
296
  def map_statistic(self, plot: ggplot):
@@ -320,6 +329,9 @@ class layer:
320
329
  if len(data) == 0:
321
330
  return
322
331
 
332
+ self.geom.params.update(self.stat.params)
333
+ self.geom.setup_params(data)
334
+ self.geom.setup_aes_params(data)
323
335
  data = self.geom.setup_data(data)
324
336
 
325
337
  check_required_aesthetics(
@@ -357,14 +369,10 @@ class layer:
357
369
  coord : coord
358
370
  Type of coordinate axes
359
371
  """
360
- params = copy(self.geom.params)
361
- params.update(self.stat.params)
362
- params["zorder"] = self.zorder
363
- params["raster"] = self.raster
364
372
  self.data = self.geom.handle_na(self.data)
365
373
  # At this point each layer must have the data
366
374
  # that is created by the plot build process
367
- self.geom.draw_layer(self.data, layout, coord, **params)
375
+ self.geom.draw_layer(self.data, layout, coord)
368
376
 
369
377
  def use_defaults(
370
378
  self,
@@ -399,7 +407,7 @@ class layer:
399
407
  """
400
408
  Prepare/modify data for plotting
401
409
  """
402
- self.stat.finish_layer(self.data, self.stat.params)
410
+ self.stat.finish_layer(self.data)
403
411
 
404
412
 
405
413
  class Layers(List[layer]):
@@ -450,7 +458,9 @@ class Layers(List[layer]):
450
458
  return [l.data for l in self]
451
459
 
452
460
  def setup(self, plot: ggplot):
453
- for l in self:
461
+ # If zorder is 0, it is left to MPL
462
+ for i, l in enumerate(self, start=1):
463
+ l.zorder = i
454
464
  l.setup(plot)
455
465
 
456
466
  def setup_data(self):
@@ -458,9 +468,7 @@ class Layers(List[layer]):
458
468
  l.setup_data()
459
469
 
460
470
  def draw(self, layout: Layout, coord: coord):
461
- # If zorder is 0, it is left to MPL
462
- for i, l in enumerate(self, start=1):
463
- l.zorder = i
471
+ for l in self:
464
472
  l.draw(layout, coord)
465
473
 
466
474
  def compute_aesthetics(self, plot: ggplot):
@@ -48,7 +48,7 @@ def factor(
48
48
  `categories` attribute (which in turn is the `categories` argument, if
49
49
  provided).
50
50
  """
51
- return pd.Categorical(values, categories=categories, ordered=None)
51
+ return pd.Categorical(values, categories=categories, ordered=None) # pyright: ignore[reportArgumentType]
52
52
 
53
53
 
54
54
  def reorder(x, y, fun=np.median, ascending=True):