From 15368ddbf5691b9bdc747e7dd2b584d36d87bafa Mon Sep 17 00:00:00 2001 From: dbrakenhoff Date: Fri, 4 Sep 2026 17:03:01 +0200 Subject: [PATCH] Fixes #239 - pass ax to adjust_text function so it doesnt default to plt.gca() - allow passing str to backgroundmap to override default provider. --- pastastore/plotting/maps.py | 93 ++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 26 deletions(-) diff --git a/pastastore/plotting/maps.py b/pastastore/plotting/maps.py index 851be534..863a236b 100644 --- a/pastastore/plotting/maps.py +++ b/pastastore/plotting/maps.py @@ -144,9 +144,10 @@ def stresses( axes handle, if not provided a new figure is created. figsize: tuple, optional figure size, by default(10, 8) - backgroundmap: bool, optional + backgroundmap: bool or str, optional if True, add background map (default CRS is EPSG:28992) with default tiles - by OpenStreetMap.Mapnik. Default option is False. + by OpenStreetMap.Mapnik. Default option is False. If str, it is passed as + map_provider to add_background_map method. label_kwargs: dict, optional dictionary with keyword arguments to pass to add_labels method show_legend : bool, optional @@ -203,7 +204,12 @@ def stresses( ax.legend(loc=(0, 1), frameon=False, ncol=5) if backgroundmap: - self.add_background_map(ax) + self.add_background_map( + ax, + map_provider=backgroundmap + if isinstance(backgroundmap, str) + else "OpenStreetMap.Mapnik", + ) return ax @@ -233,9 +239,10 @@ def oseries( automated smart label placement using adjustText, by default False figsize: tuple, optional figure size, by default(10, 8) - backgroundmap: bool, optional + backgroundmap: bool or str, optional if True, add background map (default CRS is EPSG:28992) with default tiles - by OpenStreetMap.Mapnik. Default option is False. + by OpenStreetMap.Mapnik. Default option is False. If str, it is passed as + map_provider to add_background_map method. label_kwargs: dict, optional dictionary with keyword arguments to pass to add_labels method @@ -267,7 +274,12 @@ def oseries( self.add_labels(oseries, ax, adjust=adjust, **label_kwargs) if backgroundmap: - self.add_background_map(ax) + self.add_background_map( + ax, + map_provider=backgroundmap + if isinstance(backgroundmap, str) + else "OpenStreetMap.Mapnik", + ) return ax @@ -286,9 +298,10 @@ def models( axes handle, if not provided a new figure is created. figsize: tuple, optional figure size, by default(10, 8) - backgroundmap: bool, optional + backgroundmap: bool or str, optional if True, add background map (default CRS is EPSG:28992) with default tiles - by OpenStreetMap.Mapnik. Default option is False. + by OpenStreetMap.Mapnik. Default option is False. If str, it is passed as + map_provider to add_background_map method. Returns ------- @@ -318,7 +331,12 @@ def models( self.add_labels(models, ax, adjust=adjust) if backgroundmap: - self.add_background_map(ax) + self.add_background_map( + ax, + map_provider=backgroundmap + if isinstance(backgroundmap, str) + else "OpenStreetMap.Mapnik", + ) return ax @@ -371,9 +389,10 @@ def series( axes handle, if not provided a new figure is created. figsize: tuple, optional figure size, by default(10, 8) - backgroundmap: bool, optional + backgroundmap: bool or str, optional if True, add background map (default CRS is EPSG:28992) with default tiles - by OpenStreetMap.Mapnik. Default option is False. + by OpenStreetMap.Mapnik. Default option is False. If str, it is passed as + map_provider to add_background_map method. **kwargs: dict, optional additional keyword arguments to pass to dataframe_scatter method. @@ -491,9 +510,10 @@ def dataframe( axes handle, if not provided a new figure is created. figsize: tuple, optional figuresize, by default(10, 8) - backgroundmap: bool, optional + backgroundmap: bool or str, optional if True, add background map (default CRS is EPSG:28992) with default tiles - by OpenStreetMap.Mapnik. Default option is False. + by OpenStreetMap.Mapnik. Default option is False. If str, it is passed as + map_provider to add_background_map method. progressbar: bool, optional show progressbar, default is True. @@ -549,7 +569,12 @@ def dataframe( self.add_labels(df, ax, adjust=adjust) if backgroundmap: - self.add_background_map(ax) + self.add_background_map( + ax, + map_provider=backgroundmap + if isinstance(backgroundmap, str) + else "OpenStreetMap.Mapnik", + ) return ax @@ -592,9 +617,10 @@ def modelstat( axes handle, if not provided a new figure is created. figsize: tuple, optional figuresize, by default(10, 8) - backgroundmap: bool, optional + backgroundmap: bool or str, optional if True, add background map (default CRS is EPSG:28992) with default tiles - by OpenStreetMap.Mapnik. Default option is False. + by OpenStreetMap.Mapnik. Default option is False. If str, it is passed as + map_provider to add_background_map method. progressbar: bool, optional show progressbar, default is True. @@ -675,9 +701,10 @@ def modelparam( axes handle, if not provided a new figure is created. figsize: tuple, optional figuresize, by default(10, 8) - backgroundmap: bool, optional + backgroundmap: bool or str, optional if True, add background map (default CRS is EPSG:28992) with default tiles - by OpenStreetMap.Mapnik. Default option is False. + by OpenStreetMap.Mapnik. Default option is False. If str, it is passed as + map_provider to add_background_map method. progressbar: bool, optional show progressbar, default is True @@ -758,9 +785,10 @@ def signature( axes handle, if not provided a new figure is created. figsize: tuple, optional figuresize, by default(10, 8) - backgroundmap: bool, optional + backgroundmap: bool or str, optional if True, add background map (default CRS is EPSG:28992) with default tiles - by OpenStreetMap.Mapnik. Default option is False. + by OpenStreetMap.Mapnik. Default option is False. If str, it is passed as + map_provider to add_background_map method. progressbar: bool, optional show progressbar, default is True @@ -938,9 +966,10 @@ def model( axes handle, if not provided a new figure is created. figsize: tuple, optional figsize, default is (10, 10) - backgroundmap: bool, optional + backgroundmap: bool or str, optional if True, add background map (default CRS is EPSG:28992) with default tiles - by OpenStreetMap.Mapnik. Default option is False. + by OpenStreetMap.Mapnik. Default option is False. If str, it is passed as + map_provider to add_background_map method. Returns ------- @@ -1080,7 +1109,12 @@ def model( txt.set_path_effects(stroke) if backgroundmap: - self.add_background_map(ax) + self.add_background_map( + ax, + map_provider=backgroundmap + if isinstance(backgroundmap, str) + else "OpenStreetMap.Mapnik", + ) fig.tight_layout() @@ -1126,9 +1160,10 @@ def stresslinks( adjust: bool, optional automated smart label placement using adjustText, by default False - backgroundmap: bool, optional + backgroundmap: bool or str, optional if True, add background map (default CRS is EPSG:28992) with default tiles - by OpenStreetMap.Mapnik. Default option is False. + by OpenStreetMap.Mapnik. Default option is False. If str, it is passed as + map_provider to add_background_map method. Returns ------- @@ -1226,7 +1261,12 @@ def stresslinks( ax.legend(handles=legend_elements) if backgroundmap: - self.add_background_map(ax) + self.add_background_map( + ax, + map_provider=backgroundmap + if isinstance(backgroundmap, str) + else "OpenStreetMap.Mapnik", + ) return ax @@ -1311,6 +1351,7 @@ def add_labels( adjust_text( texts, objects=objects, + ax=ax, force_text=(0.05, 0.10), **{ "arrowprops": {