@@ -220,44 +220,44 @@ def _should_request_colorbar(
220220 return bool (auto_condition )
221221
222222
223- def _apply_datashader_norm (
223+ def _apply_ds_norm (
224224 agg : Any ,
225225 norm : Normalize ,
226226) -> tuple [Any , list [float ] | None ]:
227227 """Apply norm vmin/vmax to a datashader aggregate.
228228
229229 When vmin == vmax, maps the value to 0.5 using an artificial [0, 1] span.
230- Returns (agg, ds_span ) where ds_span is None if no norm was set.
230+ Returns (agg, color_span ) where color_span is None if no norm was set.
231231 """
232232 if norm .vmin is None and norm .vmax is None :
233233 return agg , None
234234 norm .vmin = np .min (agg ) if norm .vmin is None else norm .vmin
235235 norm .vmax = np .max (agg ) if norm .vmax is None else norm .vmax
236- ds_span : list [float ] = [norm .vmin , norm .vmax ]
236+ color_span : list [float ] = [norm .vmin , norm .vmax ]
237237 if norm .vmin == norm .vmax :
238- ds_span = [0 , 1 ]
238+ color_span = [0 , 1 ]
239239 if norm .clip :
240240 agg = (agg - agg ) + 0.5
241241 else :
242242 agg = agg .where ((agg >= norm .vmin ) | (np .isnan (agg )), other = - 1 )
243243 agg = agg .where ((agg <= norm .vmin ) | (np .isnan (agg )), other = 2 )
244244 agg = agg .where ((agg != norm .vmin ) | (np .isnan (agg )), other = 0.5 )
245- return agg , ds_span
245+ return agg , color_span
246246
247247
248- def _build_datashader_colorbar_mappable (
249- aggregate_with_reduction : tuple [Any , Any ] | None ,
248+ def _build_ds_colorbar (
249+ reduction_bounds : tuple [Any , Any ] | None ,
250250 norm : Normalize ,
251251 cmap : Any ,
252252) -> ScalarMappable | None :
253253 """Create a ScalarMappable for the colorbar from datashader reduction bounds.
254254
255255 Returns None if there is no continuous reduction.
256256 """
257- if aggregate_with_reduction is None :
257+ if reduction_bounds is None :
258258 return None
259- vmin = aggregate_with_reduction [0 ].values if norm .vmin is None else norm .vmin
260- vmax = aggregate_with_reduction [1 ].values if norm .vmax is None else norm .vmax
259+ vmin = reduction_bounds [0 ].values if norm .vmin is None else norm .vmin
260+ vmax = reduction_bounds [1 ].values if norm .vmax is None else norm .vmax
261261 if (norm .vmin is not None or norm .vmax is not None ) and norm .vmin == norm .vmax :
262262 assert norm .vmin is not None
263263 assert norm .vmax is not None
@@ -269,7 +269,7 @@ def _build_datashader_colorbar_mappable(
269269 )
270270
271271
272- def _datashader_aggregate (
272+ def _ds_aggregate (
273273 cvs : Any ,
274274 transformed_element : Any ,
275275 col_for_color : str | None ,
@@ -283,10 +283,10 @@ def _datashader_aggregate(
283283 Dispatches between categorical (ds.by), continuous (reduction function),
284284 and no-color (ds.count) aggregation modes.
285285
286- Returns (agg, aggregate_with_reduction, continuous_nan_agg ).
286+ Returns (agg, reduction_bounds, nan_agg ).
287287 """
288- aggregate_with_reduction = None
289- continuous_nan_agg = None
288+ reduction_bounds = None
289+ nan_agg = None
290290
291291 def _agg_call (element : Any , agg_func : Any ) -> Any :
292292 if geom_type == "shapes" :
@@ -304,69 +304,69 @@ def _agg_call(element: Any, agg_func: Any) -> Any:
304304 "very close to the matplotlib result."
305305 )
306306 agg = _datashader_aggregate_with_function (ds_reduction , cvs , transformed_element , col_for_color , geom_type )
307- aggregate_with_reduction = (agg .min (), agg .max ())
307+ reduction_bounds = (agg .min (), agg .max ())
308308
309309 nan_elements = transformed_element [transformed_element [col_for_color ].isnull ()]
310310 if len (nan_elements ) > 0 :
311- continuous_nan_agg = _datashader_aggregate_with_function ("any" , cvs , nan_elements , None , geom_type )
311+ nan_agg = _datashader_aggregate_with_function ("any" , cvs , nan_elements , None , geom_type )
312312 else :
313313 agg = _agg_call (transformed_element , ds .count ())
314314
315- return agg , aggregate_with_reduction , continuous_nan_agg
315+ return agg , reduction_bounds , nan_agg
316316
317317
318- def _datashader_shade_continuous (
318+ def _ds_shade_continuous (
319319 agg : Any ,
320- ds_span : list [float ] | None ,
320+ color_span : list [float ] | None ,
321321 norm : Normalize ,
322322 cmap : Any ,
323323 alpha : float ,
324- aggregate_with_reduction : tuple [Any , Any ] | None ,
325- continuous_nan_agg : Any | None ,
324+ reduction_bounds : tuple [Any , Any ] | None ,
325+ nan_agg : Any | None ,
326326 na_color_hex : str ,
327327 spread_px : int | None = None ,
328328 ds_reduction : _DsReduction | None = None ,
329329) -> tuple [Any , Any | None , tuple [Any , Any ] | None ]:
330330 """Shade a continuous datashader aggregate, optionally applying spread and NaN coloring.
331331
332- Returns (ds_result, continuous_nan_shaded, aggregate_with_reduction ).
332+ Returns (shaded, nan_shaded, reduction_bounds ).
333333 """
334334 if spread_px is not None :
335335 spread_how = _datshader_get_how_kw_for_spread (ds_reduction )
336336 agg = ds .tf .spread (agg , px = spread_px , how = spread_how )
337- aggregate_with_reduction = (agg .min (), agg .max ())
337+ reduction_bounds = (agg .min (), agg .max ())
338338
339339 ds_cmap = cmap
340340 if (
341- aggregate_with_reduction is not None
342- and aggregate_with_reduction [0 ] == aggregate_with_reduction [1 ]
343- and (ds_span is None or ds_span != [0 , 1 ])
341+ reduction_bounds is not None
342+ and reduction_bounds [0 ] == reduction_bounds [1 ]
343+ and (color_span is None or color_span != [0 , 1 ])
344344 ):
345345 ds_cmap = matplotlib .colors .to_hex (cmap (0.0 ), keep_alpha = False )
346- aggregate_with_reduction = (
347- aggregate_with_reduction [0 ],
348- aggregate_with_reduction [0 ] + 1 ,
346+ reduction_bounds = (
347+ reduction_bounds [0 ],
348+ reduction_bounds [0 ] + 1 ,
349349 )
350350
351- ds_result = _datashader_map_aggregate_to_color (
351+ shaded = _datashader_map_aggregate_to_color (
352352 agg ,
353353 cmap = ds_cmap ,
354354 min_alpha = _convert_alpha_to_datashader_range (alpha ),
355- span = ds_span ,
355+ span = color_span ,
356356 clip = norm .clip ,
357357 )
358358
359- continuous_nan_shaded = None
360- if continuous_nan_agg is not None :
359+ nan_shaded = None
360+ if nan_agg is not None :
361361 shade_kwargs : dict [str , Any ] = {"cmap" : na_color_hex , "how" : "linear" }
362362 if spread_px is not None :
363- continuous_nan_agg = ds .tf .spread (continuous_nan_agg , px = spread_px , how = "max" )
363+ nan_agg = ds .tf .spread (nan_agg , px = spread_px , how = "max" )
364364 else :
365365 # only shapes (no spread) pass min_alpha for NaN shading
366366 shade_kwargs ["min_alpha" ] = _convert_alpha_to_datashader_range (alpha )
367- continuous_nan_shaded = ds .tf .shade (continuous_nan_agg , ** shade_kwargs )
367+ nan_shaded = ds .tf .shade (nan_agg , ** shade_kwargs )
368368
369- return ds_result , continuous_nan_shaded , aggregate_with_reduction
369+ return shaded , nan_shaded , reduction_bounds
370370
371371
372372def _build_color_key (
@@ -386,7 +386,7 @@ def _build_color_key(
386386 return _build_datashader_color_key (cat_series , color_vector , na_color_hex )
387387
388388
389- def _datashader_shade_categorical (
389+ def _ds_shade_categorical (
390390 agg : Any ,
391391 color_key : dict [str , str ] | None ,
392392 color_vector : Any ,
@@ -447,20 +447,20 @@ def _render_ds_outlines(
447447 _ax_show_and_transform (rgba , trans , ax , zorder = render_params .zorder , alpha = alpha , extent = extent )
448448
449449
450- def _render_datashader_result (
450+ def _render_ds_image (
451451 ax : matplotlib .axes .SubplotBase ,
452- ds_result : Any ,
452+ shaded : Any ,
453453 factor : float ,
454454 zorder : int ,
455455 alpha : float ,
456456 extent : list [float ] | None ,
457- continuous_nan_result : Any | None = None ,
457+ nan_result : Any | None = None ,
458458) -> Any :
459- """Render a shaded datashader result onto matplotlib axes, with optional NaN overlay."""
460- if continuous_nan_result is not None :
461- rgba_nan , trans_nan = _create_image_from_datashader_result (continuous_nan_result , factor , ax )
459+ """Render a shaded datashader image onto matplotlib axes, with optional NaN overlay."""
460+ if nan_result is not None :
461+ rgba_nan , trans_nan = _create_image_from_datashader_result (nan_result , factor , ax )
462462 _ax_show_and_transform (rgba_nan , trans_nan , ax , zorder = zorder , alpha = alpha , extent = extent )
463- rgba_image , trans_data = _create_image_from_datashader_result (ds_result , factor , ax )
463+ rgba_image , trans_data = _create_image_from_datashader_result (shaded , factor , ax )
464464 return _ax_show_and_transform (rgba_image , trans_data , ax , zorder = zorder , alpha = alpha , extent = extent )
465465
466466
@@ -474,7 +474,7 @@ def _make_palette(
474474 return ListedColormap (dict .fromkeys (color_vector [~ pd .Categorical (color_source_vector ).isnull ()]))
475475
476476
477- def _decorate_render (
477+ def _add_legend_and_colorbar (
478478 ax : matplotlib .axes .SubplotBase ,
479479 cax : ScalarMappable | None ,
480480 fig_params : FigParams ,
@@ -730,7 +730,7 @@ def _render_shapes(
730730 cat_series = cat_series .astype ("category" )
731731 transformed_element [col_for_color ] = cat_series
732732
733- agg , aggregate_with_reduction , continuous_nan_agg = _datashader_aggregate (
733+ agg , reduction_bounds , nan_agg = _ds_aggregate (
734734 cvs ,
735735 transformed_element ,
736736 col_for_color ,
@@ -740,7 +740,7 @@ def _render_shapes(
740740 "shapes" ,
741741 )
742742
743- agg , ds_span = _apply_datashader_norm (agg , norm )
743+ agg , color_span = _apply_ds_norm (agg , norm )
744744 na_color_hex = _hex_no_alpha (render_params .cmap_params .na_color .get_hex ())
745745 color_key = _build_color_key (
746746 transformed_element ,
@@ -750,39 +750,39 @@ def _render_shapes(
750750 na_color_hex ,
751751 )
752752
753- continuous_nan_shaded = None
753+ nan_shaded = None
754754 if color_by_categorical or col_for_color is None :
755- ds_result = _datashader_shade_categorical (
755+ shaded = _ds_shade_categorical (
756756 agg ,
757757 color_key ,
758758 color_vector ,
759759 render_params .fill_alpha ,
760760 )
761761 else :
762- ds_result , continuous_nan_shaded , aggregate_with_reduction = _datashader_shade_continuous (
762+ shaded , nan_shaded , reduction_bounds = _ds_shade_continuous (
763763 agg ,
764- ds_span ,
764+ color_span ,
765765 norm ,
766766 render_params .cmap_params .cmap ,
767767 render_params .fill_alpha ,
768- aggregate_with_reduction ,
769- continuous_nan_agg ,
768+ reduction_bounds ,
769+ nan_agg ,
770770 na_color_hex ,
771771 )
772772
773773 _render_ds_outlines (cvs , transformed_element , render_params , fig_params , ax , factor , x_ext + y_ext )
774774
775- _cax = _render_datashader_result (
775+ _cax = _render_ds_image (
776776 ax ,
777- ds_result ,
777+ shaded ,
778778 factor ,
779779 render_params .zorder ,
780780 render_params .fill_alpha ,
781781 x_ext + y_ext ,
782- continuous_nan_result = continuous_nan_shaded ,
782+ nan_result = nan_shaded ,
783783 )
784784
785- cax = _build_datashader_colorbar_mappable ( aggregate_with_reduction , norm , render_params .cmap_params .cmap )
785+ cax = _build_ds_colorbar ( reduction_bounds , norm , render_params .cmap_params .cmap )
786786
787787 elif method == "matplotlib" :
788788 # render outlines separately to ensure they are always underneath the shape
@@ -867,7 +867,7 @@ def _render_shapes(
867867 vmax = 1.0
868868 _cax .set_clim (vmin = vmin , vmax = vmax )
869869
870- _decorate_render (
870+ _add_legend_and_colorbar (
871871 ax = ax ,
872872 cax = cax ,
873873 fig_params = fig_params ,
@@ -1121,7 +1121,7 @@ def _render_points(
11211121 if color_by_categorical and not isinstance (color_dtype , pd .CategoricalDtype ):
11221122 transformed_element [col_for_color ] = transformed_element [col_for_color ].astype ("category" )
11231123
1124- agg , aggregate_with_reduction , continuous_nan_agg = _datashader_aggregate (
1124+ agg , reduction_bounds , nan_agg = _ds_aggregate (
11251125 cvs ,
11261126 transformed_element ,
11271127 col_for_color ,
@@ -1131,7 +1131,7 @@ def _render_points(
11311131 "points" ,
11321132 )
11331133
1134- agg , ds_span = _apply_datashader_norm (agg , norm )
1134+ agg , color_span = _apply_ds_norm (agg , norm )
11351135 na_color_hex = _hex_no_alpha (render_params .cmap_params .na_color .get_hex ())
11361136 color_key = _build_color_key (
11371137 transformed_element ,
@@ -1149,40 +1149,40 @@ def _render_points(
11491149 ):
11501150 color_vector = np .asarray ([_hex_no_alpha (x ) for x in color_vector ])
11511151
1152- continuous_nan_shaded = None
1152+ nan_shaded = None
11531153 if color_by_categorical or col_for_color is None :
1154- ds_result = _datashader_shade_categorical (
1154+ shaded = _ds_shade_categorical (
11551155 agg ,
11561156 color_key ,
11571157 color_vector ,
11581158 render_params .alpha ,
11591159 spread_px = px ,
11601160 )
11611161 else :
1162- ds_result , continuous_nan_shaded , aggregate_with_reduction = _datashader_shade_continuous (
1162+ shaded , nan_shaded , reduction_bounds = _ds_shade_continuous (
11631163 agg ,
1164- ds_span ,
1164+ color_span ,
11651165 norm ,
11661166 render_params .cmap_params .cmap ,
11671167 render_params .alpha ,
1168- aggregate_with_reduction ,
1169- continuous_nan_agg ,
1168+ reduction_bounds ,
1169+ nan_agg ,
11701170 na_color_hex ,
11711171 spread_px = px ,
11721172 ds_reduction = render_params .ds_reduction ,
11731173 )
11741174
1175- _render_datashader_result (
1175+ _render_ds_image (
11761176 ax ,
1177- ds_result ,
1177+ shaded ,
11781178 factor ,
11791179 render_params .zorder ,
11801180 render_params .alpha ,
11811181 x_ext + y_ext ,
1182- continuous_nan_result = continuous_nan_shaded ,
1182+ nan_result = nan_shaded ,
11831183 )
11841184
1185- cax = _build_datashader_colorbar_mappable ( aggregate_with_reduction , norm , render_params .cmap_params .cmap )
1185+ cax = _build_ds_colorbar ( reduction_bounds , norm , render_params .cmap_params .cmap )
11861186
11871187 elif method == "matplotlib" :
11881188 # update axis limits if plot was empty before (necessary if datashader comes after)
@@ -1207,7 +1207,7 @@ def _render_points(
12071207 ax .set_xbound (extent ["x" ])
12081208 ax .set_ybound (extent ["y" ])
12091209
1210- _decorate_render (
1210+ _add_legend_and_colorbar (
12111211 ax = ax ,
12121212 cax = cax ,
12131213 fig_params = fig_params ,
0 commit comments