@@ -236,15 +236,14 @@ def _render_shapes(
236236 norm .vmax = np .max (agg ) if norm .vmax is None else norm .vmax
237237 ds_span = [norm .vmin , norm .vmax ]
238238 if norm .vmin == norm .vmax :
239+ # edge case, value vmin is rendered as the middle of the cmap
240+ ds_span = [0 , 1 ]
239241 if norm .clip :
240- # all data is mapped to 0
241- agg = agg - agg
242+ agg = (agg - agg ) + 0.5
242243 else :
243- # values equal to norm.vmin are mapped to 0, the rest to -1 or 1
244244 agg = agg .where ((agg >= norm .vmin ) | (np .isnan (agg )), other = - 1 )
245- agg = agg .where ((agg <= norm .vmin ) | (np .isnan (agg )), other = 1 )
246- agg = agg .where ((agg != norm .vmin ) | (np .isnan (agg )), other = 0 )
247- ds_span = [- 1 , 1 ]
245+ agg = agg .where ((agg <= norm .vmin ) | (np .isnan (agg )), other = 2 )
246+ agg = agg .where ((agg != norm .vmin ) | (np .isnan (agg )), other = 0.5 )
248247
249248 color_key = (
250249 [x [:- 2 ] for x in color_vector .categories .values ]
@@ -326,8 +325,8 @@ def _render_shapes(
326325 vmin = aggregate_with_reduction [0 ].values if norm .vmin is None else norm .vmin
327326 vmax = aggregate_with_reduction [1 ].values if norm .vmin is None else norm .vmax
328327 if (norm .vmin is not None or norm .vmax is not None ) and norm .vmin == norm .vmax :
329- vmin = norm .vmin
330- vmax = norm .vmin + 1
328+ vmin = norm .vmin - 0.5
329+ vmax = norm .vmin + 0.5
331330 cax = ScalarMappable (
332331 norm = matplotlib .colors .Normalize (vmin = vmin , vmax = vmax ),
333332 cmap = render_params .cmap_params .cmap ,
@@ -596,15 +595,15 @@ def _render_points(
596595 norm .vmax = np .max (agg ) if norm .vmax is None else norm .vmax
597596 ds_span = [norm .vmin , norm .vmax ]
598597 if norm .vmin == norm .vmax :
598+ ds_span = [0 , 1 ]
599599 if norm .clip :
600- # all data is mapped to 0
601- agg = agg - agg
600+ # all data is mapped to 0.5
601+ agg = ( agg - agg ) + 0.5
602602 else :
603- # values equal to norm.vmin are mapped to 0, the rest to -1 or 1
603+ # values equal to norm.vmin are mapped to 0.5 , the rest to -1 or 2
604604 agg = agg .where ((agg >= norm .vmin ) | (np .isnan (agg )), other = - 1 )
605- agg = agg .where ((agg <= norm .vmin ) | (np .isnan (agg )), other = 1 )
606- agg = agg .where ((agg != norm .vmin ) | (np .isnan (agg )), other = 0 )
607- ds_span = [- 1 , 1 ]
605+ agg = agg .where ((agg <= norm .vmin ) | (np .isnan (agg )), other = 2 )
606+ agg = agg .where ((agg != norm .vmin ) | (np .isnan (agg )), other = 0.5 )
608607
609608 color_key = (
610609 list (color_vector .categories .values )
@@ -637,7 +636,7 @@ def _render_points(
637636 # in case all elements have the same value X: we render them using cmap(0.0),
638637 # using an artificial "span" of [X, X + 1] for the color bar
639638 # else: all elements would get alpha=0 and the color bar would have a weird range
640- if aggregate_with_reduction [0 ] == aggregate_with_reduction [1 ]:
639+ if aggregate_with_reduction [0 ] == aggregate_with_reduction [1 ] and ( ds_span is None or ds_span != [ 0 , 1 ]) :
641640 ds_cmap = matplotlib .colors .to_hex (render_params .cmap_params .cmap (0.0 ), keep_alpha = False )
642641 aggregate_with_reduction = (aggregate_with_reduction [0 ], aggregate_with_reduction [0 ] + 1 )
643642
@@ -646,6 +645,7 @@ def _render_points(
646645 cmap = ds_cmap ,
647646 span = ds_span ,
648647 clip = norm .clip ,
648+ min_alpha = np .min ([254 , render_params .alpha * 255 ]),
649649 )
650650
651651 rgba_image , trans_data = _create_image_from_datashader_result (ds_result , factor , ax )
@@ -663,12 +663,14 @@ def _render_points(
663663 vmin = aggregate_with_reduction [0 ].values if norm .vmin is None else norm .vmin
664664 vmax = aggregate_with_reduction [1 ].values if norm .vmax is None else norm .vmax
665665 if (norm .vmin is not None or norm .vmax is not None ) and norm .vmin == norm .vmax :
666- if norm .clip :
667- vmin = norm .vmin
668- vmax = norm .vmin + 1
669- else :
670- vmin = norm .vmin - 0.5
671- vmax = norm .vmin + 0.5
666+ vmin = norm .vmin - 0.5
667+ vmax = norm .vmin + 0.5
668+ # if norm.clip:
669+ # vmin = norm.vmin
670+ # vmax = norm.vmin + 1
671+ # else:
672+ # vmin = norm.vmin - 0.5
673+ # vmax = norm.vmin + 0.5
672674 cax = ScalarMappable (
673675 norm = matplotlib .colors .Normalize (vmin = vmin , vmax = vmax ),
674676 cmap = render_params .cmap_params .cmap ,
0 commit comments