@@ -1233,7 +1233,7 @@ def _parse_vert(
12331233 return kwargs
12341234
12351235
1236- def _seaborn_call ():
1236+ def _inside_seaborn_call ():
12371237 """
12381238 Try to detect `seaborn` calls to `scatter` and `bar` and then automatically
12391239 apply `absolute_size` and `absolute_width`.
@@ -1404,21 +1404,6 @@ def _add_collection_labels(
14041404 obj .set_edgecolors (edgecolors )
14051405 return labs
14061406
1407- def _add_contour_edge (self , method , * args , ** kwargs ):
1408- """
1409- Call the contour method to add "edges" to filled contours.
1410- """
1411- # NOTE: This is used to provide an object that can be used by 'clabel' for
1412- # auto-labels. Filled contours create strange artifacts.
1413- # NOTE: Make the default 'line width' identical to one used for pcolor plots
1414- # rather than rc['contour.linewidth']. See mpl pcolor() source code
1415- if not any (key in kwargs for key in ('linewidths' , 'linestyles' , 'edgecolors' )):
1416- kwargs ['linewidths' ] = 0 # for clabel
1417- kwargs .setdefault ('linewidths' , EDGEWIDTH )
1418- kwargs .pop ('cmap' , None )
1419- kwargs ['colors' ] = kwargs .pop ('edgecolors' , 'k' )
1420- return self ._plot_native (method , * args , ** kwargs )
1421-
14221407 def _add_contour_labels (
14231408 self , obj , cobj , fmt , * , c = None , color = None , colors = None ,
14241409 size = None , fontsize = None , inline_spacing = None , ** kwargs
@@ -1636,9 +1621,25 @@ def _add_error_shading(
16361621 kwargs ['distribution' ] = distribution
16371622 return (* eobjs , kwargs )
16381623
1639- def _add_edge_fix (self , obj , edgefix = None , ** kwargs ):
1624+ def _fix_contour_edges (self , method , * args , ** kwargs ):
1625+ """
1626+ Fix the filled contour edges by secretly adding solid contours with
1627+ the same input data.
16401628 """
1641- Fix white lines between between filled contours and mesh and fix issues
1629+ # NOTE: This is used to provide an object that can be used by 'clabel' for
1630+ # auto-labels. Filled contours create strange artifacts.
1631+ # NOTE: Make the default 'line width' identical to one used for pcolor plots
1632+ # rather than rc['contour.linewidth']. See mpl pcolor() source code
1633+ if not any (key in kwargs for key in ('linewidths' , 'linestyles' , 'edgecolors' )):
1634+ kwargs ['linewidths' ] = 0 # for clabel
1635+ kwargs .setdefault ('linewidths' , EDGEWIDTH )
1636+ kwargs .pop ('cmap' , None )
1637+ kwargs ['colors' ] = kwargs .pop ('edgecolors' , 'k' )
1638+ return self ._plot_native (method , * args , ** kwargs )
1639+
1640+ def _fix_patch_edges (self , obj , edgefix = None , ** kwargs ):
1641+ """
1642+ Fix white lines between between filled patches and fix issues
16421643 with colormaps that are transparent. If keyword args passed by user
16431644 include explicit edge properties then we skip this step.
16441645 """
@@ -1685,17 +1686,17 @@ def _add_edge_fix(self, obj, edgefix=None, **kwargs):
16851686 obj .set_edgecolor (obj .get_facecolor ())
16861687 elif np .iterable (obj ): # e.g. silent_list of BarContainer
16871688 for element in obj :
1688- self ._add_edge_fix (element , edgefix = edgefix )
1689+ self ._fix_patch_edges (element , edgefix = edgefix )
16891690 else :
1690- warnings ._warn_proplot (f'Unexpected object { obj } passed to _add_edge_fix .' )
1691+ warnings ._warn_proplot (f'Unexpected obj { obj } passed to _fix_patch_edges .' )
16911692
1692- def _add_sticky_edges (self , objs , axis , * args , only = None ):
1693+ def _fix_sticky_edges (self , objs , axis , * args , only = None ):
16931694 """
1694- Add sticky edges to the input artists using the minimum and maximum of the
1695+ Fix sticky edges for the input artists using the minimum and maximum of the
16951696 input coordinates. This is used to copy `bar` behavior to `area` and `lines`.
16961697 """
1697- for sides in args :
1698- min_ , max_ = inputs ._safe_range (sides )
1698+ for array in args :
1699+ min_ , max_ = inputs ._safe_range (array )
16991700 if min_ is None or max_ is None :
17001701 continue
17011702 for obj in guides ._iter_iterables (objs ):
@@ -2734,7 +2735,7 @@ def _apply_plot(self, *pairs, vert=True, **kwargs):
27342735 objs .append ((* eb , * es , obj ) if eb or es else obj )
27352736
27362737 # Add sticky edges
2737- self ._add_sticky_edges (objs , 'x' if vert else 'y' , * xsides , only = mlines .Line2D )
2738+ self ._fix_sticky_edges (objs , 'x' if vert else 'y' , * xsides , only = mlines .Line2D )
27382739 self ._update_guide (objs , ** guide_kw )
27392740 return cbook .silent_list ('Line2D' , objs ) # always return list
27402741
@@ -3012,7 +3013,7 @@ def _apply_lines(
30123013 objs .append (obj )
30133014
30143015 # Draw guide and add sticky edges
3015- self ._add_sticky_edges (objs , 'y' if vert else 'x' , * sides )
3016+ self ._fix_sticky_edges (objs , 'y' if vert else 'x' , * sides )
30163017 self ._update_guide (objs , ** guide_kw )
30173018 return (
30183019 objs [0 ] if len (objs ) == 1
@@ -3055,7 +3056,7 @@ def _parse_markersize(
30553056 s .flat [:] = utils .units (s .flat , 'pt' )
30563057 s = s .astype (np .float ) ** 2
30573058 if absolute_size is None :
3058- if _seaborn_call ():
3059+ if _inside_seaborn_call ():
30593060 absolute_size = True
30603061 else :
30613062 absolute_size = default_size
@@ -3171,7 +3172,7 @@ def _apply_fill(
31713172 name = 'fill_between' if vert else 'fill_betweenx'
31723173 stack = _not_none (stack = stack , stacked = stacked )
31733174 xs , ys1 , ys2 , kw = self ._parse_1d_plot (xs , ys1 , ys2 , vert = vert , ** kw )
3174- edgefix_kw = _pop_params (kw , self ._add_edge_fix )
3175+ edgefix_kw = _pop_params (kw , self ._fix_patch_edges )
31753176
31763177 # Draw patches with default edge width zero
31773178 y0 = 0
@@ -3187,7 +3188,7 @@ def _apply_fill(
31873188 obj = self ._plot_negpos (name , x , y1 , y2 , where = w , use_where = True , ** kw ) # noqa: E501
31883189 else :
31893190 obj = self ._plot_native (name , x , y1 , y2 , where = w , ** kw )
3190- self ._add_edge_fix (obj , ** edgefix_kw , ** kw )
3191+ self ._fix_patch_edges (obj , ** edgefix_kw , ** kw )
31913192 xsides .append (x )
31923193 for y in (y1 , y2 ):
31933194 self ._inbounds_xylim (extents , x , y , vert = vert )
@@ -3198,7 +3199,7 @@ def _apply_fill(
31983199 # Draw guide and add sticky edges
31993200 self ._update_guide (objs , ** guide_kw )
32003201 for axis , sides in zip ('xy' if vert else 'yx' , (xsides , ysides )):
3201- self ._add_sticky_edges (objs , axis , * sides )
3202+ self ._fix_sticky_edges (objs , axis , * sides )
32023203 return (
32033204 objs [0 ] if len (objs ) == 1
32043205 else cbook .silent_list ('PolyCollection' , objs )
@@ -3274,9 +3275,9 @@ def _apply_bar(
32743275 name = 'barh' if orientation == 'horizontal' else 'bar'
32753276 stack = _not_none (stack = stack , stacked = stacked )
32763277 xs , hs , kw = self ._parse_1d_plot (xs , hs , orientation = orientation , ** kw )
3277- edgefix_kw = _pop_params (kw , self ._add_edge_fix )
3278+ edgefix_kw = _pop_params (kw , self ._fix_patch_edges )
32783279 if absolute_width is None :
3279- absolute_width = _seaborn_call ()
3280+ absolute_width = _inside_seaborn_call ()
32803281
32813282 # Call func after converting bar width
32823283 b0 = 0
@@ -3304,7 +3305,7 @@ def _apply_bar(
33043305 obj = self ._plot_negpos (name , x , h , w , b , use_zero = True , ** kw )
33053306 else :
33063307 obj = self ._plot_native (name , x , h , w , b , ** kw )
3307- self ._add_edge_fix (obj , ** edgefix_kw , ** kw )
3308+ self ._fix_patch_edges (obj , ** edgefix_kw , ** kw )
33083309 for y in (b , b + h ):
33093310 self ._inbounds_xylim (extents , x , y , orientation = orientation )
33103311 objs .append ((* eb , obj ) if eb else obj )
@@ -3349,13 +3350,13 @@ def pie(self, x, explode, *, labelpad=None, labeldistance=None, **kwargs):
33493350 kw = kwargs .copy ()
33503351 pad = _not_none (labeldistance = labeldistance , labelpad = labelpad , default = 1.15 )
33513352 props = _pop_props (kw , 'patch' )
3352- edgefix_kw = _pop_params (kw , self ._add_edge_fix )
3353+ edgefix_kw = _pop_params (kw , self ._fix_patch_edges )
33533354 _ , x , kw = self ._parse_1d_plot (x , autox = False , autoy = False , ** kw )
33543355 kw = self ._parse_cycle (x .size , ** kw )
33553356 kw ['labeldistance' ] = pad
33563357 objs = self ._plot_native ('pie' , x , explode , wedgeprops = props , ** kw )
33573358 objs = tuple (cbook .silent_list (type (seq [0 ]).__name__ , seq ) for seq in objs )
3358- self ._add_edge_fix (objs [0 ], ** edgefix_kw , ** props )
3359+ self ._fix_patch_edges (objs [0 ], ** edgefix_kw , ** props )
33593360 return objs
33603361
33613362 @staticmethod
@@ -3637,13 +3638,13 @@ def _apply_hist(
36373638 kw ['rwidth' ] = _not_none (width = width , rwidth = rwidth ) # latter is native
36383639 kw ['histtype' ] = histtype = _not_none (histtype , 'bar' )
36393640 kw .update (_pop_props (kw , 'patch' ))
3640- edgefix_kw = _pop_params (kw , self ._add_edge_fix )
3641+ edgefix_kw = _pop_params (kw , self ._fix_patch_edges )
36413642 guide_kw = _pop_params (kw , self ._update_guide )
36423643 n = xs .shape [1 ] if xs .ndim > 1 else 1
36433644 kw = self ._parse_cycle (n , ** kw )
36443645 obj = self ._plot_native ('hist' , xs , orientation = orientation , ** kw )
36453646 if histtype .startswith ('bar' ):
3646- self ._add_edge_fix (obj [2 ], ** edgefix_kw , ** kw )
3647+ self ._fix_patch_edges (obj [2 ], ** edgefix_kw , ** kw )
36473648 # Revert to mpl < 3.3 behavior where silent_list was always returned for
36483649 # non-bar-type histograms. Because consistency.
36493650 res = obj [2 ]
@@ -3744,15 +3745,15 @@ def contourf(self, x, y, z, **kwargs):
37443745 kw .update (_pop_props (kw , 'collection' ))
37453746 kw = self ._parse_cmap (x , y , z , plot_contours = True , ** kw )
37463747 contour_kw = _pop_kwargs (kw , 'edgecolors' , 'linewidths' , 'linestyles' )
3747- edgefix_kw = _pop_params (kw , self ._add_edge_fix )
3748+ edgefix_kw = _pop_params (kw , self ._fix_patch_edges )
37483749 labels_kw = _pop_params (kw , self ._add_auto_labels )
37493750 guide_kw = _pop_params (kw , self ._update_guide )
37503751 label = kw .pop ('label' , None )
37513752 m = cm = self ._plot_native ('contourf' , x , y , z , ** kw )
37523753 m ._legend_label = label
3753- self ._add_edge_fix (m , ** edgefix_kw , ** contour_kw ) # skipped if not contour_kw
3754+ self ._fix_patch_edges (m , ** edgefix_kw , ** contour_kw ) # no-op if not contour_kw
37543755 if contour_kw or labels_kw :
3755- cm = self ._add_contour_edge ('contour' , x , y , z , ** kw , ** contour_kw )
3756+ cm = self ._fix_contour_edges ('contour' , x , y , z , ** kw , ** contour_kw )
37563757 self ._add_auto_labels (m , cm , ** labels_kw )
37573758 self ._update_guide (m , queue_colorbar = False , ** guide_kw )
37583759 return m
@@ -3767,7 +3768,7 @@ def pcolor(self, x, y, z, **kwargs):
37673768 x , y , z , kw = self ._parse_2d_plot (x , y , z , edges = True , ** kwargs )
37683769 kw .update (_pop_props (kw , 'collection' ))
37693770 kw = self ._parse_cmap (x , y , z , to_centers = True , ** kw )
3770- edgefix_kw = _pop_params (kw , self ._add_edge_fix )
3771+ edgefix_kw = _pop_params (kw , self ._fix_patch_edges )
37713772 labels_kw = _pop_params (kw , self ._add_auto_labels )
37723773 guide_kw = _pop_params (kw , self ._update_guide )
37733774 with self ._keep_grid_bools ():
@@ -3787,7 +3788,7 @@ def pcolormesh(self, x, y, z, **kwargs):
37873788 x , y , z , kw = self ._parse_2d_plot (x , y , z , edges = True , ** kwargs )
37883789 kw .update (_pop_props (kw , 'collection' ))
37893790 kw = self ._parse_cmap (x , y , z , to_centers = True , ** kw )
3790- edgefix_kw = _pop_params (kw , self ._add_edge_fix )
3791+ edgefix_kw = _pop_params (kw , self ._fix_patch_edges )
37913792 labels_kw = _pop_params (kw , self ._add_auto_labels )
37923793 guide_kw = _pop_params (kw , self ._update_guide )
37933794 with self ._keep_grid_bools ():
@@ -3807,13 +3808,13 @@ def pcolorfast(self, x, y, z, **kwargs):
38073808 x , y , z , kw = self ._parse_2d_plot (x , y , z , edges = True , ** kwargs )
38083809 kw .update (_pop_props (kw , 'collection' ))
38093810 kw = self ._parse_cmap (x , y , z , to_centers = True , ** kw )
3810- edgefix_kw = _pop_params (kw , self ._add_edge_fix )
3811+ edgefix_kw = _pop_params (kw , self ._fix_patch_edges )
38113812 labels_kw = _pop_params (kw , self ._add_auto_labels )
38123813 guide_kw = _pop_params (kw , self ._update_guide )
38133814 with self ._keep_grid_bools ():
38143815 m = self ._plot_native ('pcolorfast' , x , y , z , ** kw )
38153816 if not isinstance (m , mimage .AxesImage ): # NOTE: PcolorImage is derivative
3816- self ._add_edge_fix (m , ** edgefix_kw , ** kw )
3817+ self ._fix_patch_edges (m , ** edgefix_kw , ** kw )
38173818 self ._add_auto_labels (m , ** labels_kw )
38183819 elif edgefix_kw or labels_kw :
38193820 kw = {** edgefix_kw , ** labels_kw }
@@ -3831,28 +3832,28 @@ def heatmap(self, *args, aspect=None, **kwargs):
38313832 """
38323833 obj = self .pcolormesh (* args , default_discrete = False , ** kwargs )
38333834 aspect = _not_none (aspect , rc ['image.aspect' ])
3834- if self ._name == 'cartesian' :
3835- coords = getattr (obj , '_coordinates' , None )
3836- xlocator = ylocator = None
3837- if coords is not None :
3838- coords = 0.5 * (coords [1 :, ...] + coords [:- 1 , ...])
3839- coords = 0.5 * (coords [:, 1 :, :] + coords [:, :- 1 , :])
3840- xlocator , ylocator = coords [0 , :, 0 ], coords [:, 0 , 1 ]
3841- kw = {'aspect' : aspect , 'xgrid' : False , 'ygrid' : False }
3842- if xlocator is not None and self .xaxis .isDefault_majloc :
3843- kw ['xlocator' ] = xlocator
3844- if ylocator is not None and self .yaxis .isDefault_majloc :
3845- kw ['ylocator' ] = ylocator
3846- if self .xaxis .isDefault_minloc :
3847- kw ['xtickminor' ] = False
3848- if self .yaxis .isDefault_minloc :
3849- kw ['ytickminor' ] = False
3850- self .format (** kw )
3851- else :
3835+ if self ._name != 'cartesian' :
38523836 warnings ._warn_proplot (
3853- 'The heatmap() command is meant for CartesianAxes. '
3854- 'Please use pcolor() or pcolormesh() instead.'
3837+ 'The heatmap() command is meant for CartesianAxes '
3838+ 'only. Please use pcolor() or pcolormesh() instead.'
38553839 )
3840+ return obj
3841+ coords = getattr (obj , '_coordinates' , None )
3842+ xlocator = ylocator = None
3843+ if coords is not None :
3844+ coords = 0.5 * (coords [1 :, ...] + coords [:- 1 , ...])
3845+ coords = 0.5 * (coords [:, 1 :, :] + coords [:, :- 1 , :])
3846+ xlocator , ylocator = coords [0 , :, 0 ], coords [:, 0 , 1 ]
3847+ kw = {'aspect' : aspect , 'xgrid' : False , 'ygrid' : False }
3848+ if xlocator is not None and self .xaxis .isDefault_majloc :
3849+ kw ['xlocator' ] = xlocator
3850+ if ylocator is not None and self .yaxis .isDefault_majloc :
3851+ kw ['ylocator' ] = ylocator
3852+ if self .xaxis .isDefault_minloc :
3853+ kw ['xtickminor' ] = False
3854+ if self .yaxis .isDefault_minloc :
3855+ kw ['ytickminor' ] = False
3856+ self .format (** kw )
38563857 return obj
38573858
38583859 @inputs ._preprocess_args ('x' , 'y' , 'u' , 'v' , ('c' , 'color' , 'colors' ))
@@ -3962,15 +3963,15 @@ def tricontourf(self, x, y, z, **kwargs):
39623963 kw .update (_pop_props (kw , 'collection' ))
39633964 contour_kw = _pop_kwargs (kw , 'edgecolors' , 'linewidths' , 'linestyles' )
39643965 kw = self ._parse_cmap (x , y , z , plot_contours = True , ** kw )
3965- edgefix_kw = _pop_params (kw , self ._add_edge_fix )
3966+ edgefix_kw = _pop_params (kw , self ._fix_patch_edges )
39663967 labels_kw = _pop_params (kw , self ._add_auto_labels )
39673968 guide_kw = _pop_params (kw , self ._update_guide )
39683969 label = kw .pop ('label' , None )
39693970 m = cm = self ._plot_native ('tricontourf' , x , y , z , ** kw )
39703971 m ._legend_label = label
3971- self ._add_edge_fix (m , ** edgefix_kw , ** contour_kw ) # skipped if not contour_kw
3972+ self ._fix_patch_edges (m , ** edgefix_kw , ** contour_kw ) # no-op if not contour_kw
39723973 if contour_kw or labels_kw :
3973- cm = self ._add_contour_edge ('tricontour' , x , y , z , ** kw , ** contour_kw )
3974+ cm = self ._fix_contour_edges ('tricontour' , x , y , z , ** kw , ** contour_kw )
39743975 self ._add_auto_labels (m , cm , ** labels_kw )
39753976 self ._update_guide (m , queue_colorbar = False , ** guide_kw )
39763977 return m
@@ -3987,7 +3988,7 @@ def tripcolor(self, x, y, z, **kwargs):
39873988 raise ValueError ('Three input arguments are required.' )
39883989 kw .update (_pop_props (kw , 'collection' ))
39893990 kw = self ._parse_cmap (x , y , z , ** kw )
3990- edgefix_kw = _pop_params (kw , self ._add_edge_fix )
3991+ edgefix_kw = _pop_params (kw , self ._fix_patch_edges )
39913992 labels_kw = _pop_params (kw , self ._add_auto_labels )
39923993 guide_kw = _pop_params (kw , self ._update_guide )
39933994 with self ._keep_grid_bools ():
0 commit comments