@@ -663,7 +663,13 @@ def geo_scatter_categorical(
663663 return axes
664664
665665
666- def make_map (num_sub = 1 , figsize = (9 , 13 ), proj = ccrs .PlateCarree (), adapt_fontsize = True ):
666+ def make_map (
667+ num_sub = 1 ,
668+ figsize = (9 , 13 ),
669+ proj = ccrs .PlateCarree (),
670+ adapt_fontsize = True ,
671+ draw_gridlines = True ,
672+ ):
667673 """
668674 Create map figure with cartopy.
669675
@@ -680,6 +686,9 @@ def make_map(num_sub=1, figsize=(9, 13), proj=ccrs.PlateCarree(), adapt_fontsize
680686 adapt_fontsize : bool, optional
681687 If set to true, the size of the fonts will be adapted to the size of the figure. Otherwise
682688 the default matplotlib font size is used. Default is True.
689+ draw_gridlines : bool, optional
690+ If set to true, latitude/longitude gridlines are added to each map axis.
691+ Default is True.
683692
684693 Returns
685694 -------
@@ -697,22 +706,23 @@ def make_map(num_sub=1, figsize=(9, 13), proj=ccrs.PlateCarree(), adapt_fontsize
697706 if not isinstance (axis_sub , np .ndarray ):
698707 axes_iter = np .array ([[axis_sub ]])
699708
709+ fontsize = None
700710 for axis in axes_iter .flatten ():
701- try :
711+ # TODO: reactivate dynamic font size and labels once the bug in cartopy's `gridlines` is fixed
712+ # see https://github.com/matplotlib/matplotlib/issues/31926
713+ if draw_gridlines :
702714 grid = axis .gridlines (draw_labels = True , alpha = 0.2 , transform = proj )
703- grid .top_labels = grid .right_labels = False
715+ if adapt_fontsize :
716+ fontsize = max (10 , int (axis .bbox .width / 35 ))
717+ # dynamic font size for grid xlabel fails for a bug in cartopy's `gridlines`
718+ #grid.xlabel_style = {"size": fontsize}
719+ grid .xlabel_style = {"size" : 10 }
720+ grid .ylabel_style = {"size" : fontsize }
721+ # dismissing the top labels does not work for a bug in catopry's `gridlines`
722+ #grid.top_labels = False
723+ grid .right_labels = False
704724 grid .xformatter = LONGITUDE_FORMATTER
705725 grid .yformatter = LATITUDE_FORMATTER
706- if adapt_fontsize :
707- fontsize = axis .bbox .width / 35
708- if fontsize < 10 :
709- fontsize = 10
710- grid .xlabel_style = {"size" : fontsize }
711- grid .ylabel_style = {"size" : fontsize }
712- else :
713- fontsize = None
714- except TypeError :
715- pass
716726
717727 if num_col > 1 :
718728 fig .subplots_adjust (wspace = 0.3 )
0 commit comments