diff --git a/mapclassify/tests/baseline_images/test_value_by_alpha/crs_labels.png b/mapclassify/tests/baseline_images/test_value_by_alpha/crs_labels.png new file mode 100644 index 0000000..cd23ad7 Binary files /dev/null and b/mapclassify/tests/baseline_images/test_value_by_alpha/crs_labels.png differ diff --git a/mapclassify/tests/test_value_by_alpha.py b/mapclassify/tests/test_value_by_alpha.py index 0b2c10d..46f5d5c 100644 --- a/mapclassify/tests/test_value_by_alpha.py +++ b/mapclassify/tests/test_value_by_alpha.py @@ -4,9 +4,13 @@ import matplotlib.pyplot as plt import pytest from matplotlib.testing.decorators import image_comparison +from packaging.version import Version from mapclassify import shift_colormap, truncate_colormap, vba_choropleth +# see gh#305 +GPD_GT_113 = Version(geopandas.__version__) > Version("1.1.3") + class TestValueByAlphaChoropleth: def setup_method(self): @@ -129,3 +133,11 @@ def test_legend_kwargs(self): assert isinstance(fig, matplotlib.figure.Figure) assert isinstance(ax, matplotlib.axes.Axes) + + @pytest.mark.skipif(not GPD_GT_113, reason="See GH#305") + @image_comparison(["crs_labels"], **pytest.image_comp_kws) + def test_crs_labels(self): + fig, ax = vba_choropleth(self.x, self.y, self.gdf, axis_labels=True) + + assert isinstance(fig, matplotlib.figure.Figure) + assert isinstance(ax, matplotlib.axes.Axes) diff --git a/mapclassify/value_by_alpha.py b/mapclassify/value_by_alpha.py index 7edca15..ef4fdb1 100644 --- a/mapclassify/value_by_alpha.py +++ b/mapclassify/value_by_alpha.py @@ -51,6 +51,7 @@ def vba_choropleth( legend=False, legend_kwargs=None, min_alpha=0.2, + axis_labels=False, ): """Generate Value by Alpha Choropleth plots. @@ -91,13 +92,17 @@ def vba_choropleth( Keyword arguments for the legend. min_alpha : float = 0.2 Minimum alpha threshold to prevent fully transparent masking. + axis_labels : bool = False + Remove CRS unit axis labels from the returned ``ax``. This retains default + behavior in ``mapclassify`` and only has an affect when ``geopandas>v1.1.3`` + is installed. Returns ------- fig : matplotlip Figure instance - Figure of Value by Alpha choropleth + Figure of Value by Alpha choropleth. ax : matplotlib Axes instance - Axes in which the figure is plotted + Axes in which the figure is plotted. Examples -------- @@ -206,6 +211,10 @@ def vba_choropleth( ) gdf.plot(color=rgba, ax=ax) + if not axis_labels: + ax.set_xlabel("") + ax.set_ylabel("") + if legend: left, bottom, width, height = [0, 0.5, 0.2, 0.2] ax2 = fig.add_axes([left, bottom, width, height])