From c0af1cc06c77d2ce4558ebc81878f9393cafc1cf Mon Sep 17 00:00:00 2001 From: Neil Girdhar Date: Tue, 3 Oct 2023 18:43:31 -0400 Subject: [PATCH] Fix matplotlib missing get_offset_position crash * Update matplotlib test versions --- CHANGELOG.md | 5 +++++ .../plotly/matplotlylib/mplexporter/exporter.py | 12 +++++++++--- .../test_requirements/requirements_37_optional.txt | 4 ++-- .../test_requirements/requirements_38_optional.txt | 2 +- .../test_requirements/requirements_39_optional.txt | 4 ++-- .../requirements_39_pandas_2_optional.txt | 4 ++-- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbcd74579a8..895f7e7c72f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [UNRELEASED] + +### Fixed +- Repair crash on Matplotlib 3.8 related to get_offset_position [[#4372](https://github.com/plotly/plotly.py/pull/4372)], + ## [5.17.0] - 2023-09-15 ### Updated diff --git a/packages/python/plotly/plotly/matplotlylib/mplexporter/exporter.py b/packages/python/plotly/plotly/matplotlylib/mplexporter/exporter.py index 9824d274c1c..dc3a0b08d8e 100644 --- a/packages/python/plotly/plotly/matplotlylib/mplexporter/exporter.py +++ b/packages/python/plotly/plotly/matplotlylib/mplexporter/exporter.py @@ -96,7 +96,7 @@ def process_transform( code = "display" if ax is not None: - for (c, trans) in [ + for c, trans in [ ("data", ax.transData), ("axes", ax.transAxes), ("figure", ax.figure.transFigure), @@ -130,7 +130,7 @@ def crawl_ax(self, ax): self.draw_line(ax, line) for text in ax.texts: self.draw_text(ax, text) - for (text, ttp) in zip( + for text, ttp in zip( [ax.xaxis.label, ax.yaxis.label, ax.title], ["xlabel", "ylabel", "title"], ): @@ -285,8 +285,14 @@ def draw_collection( "zorder": collection.get_zorder(), } + # TODO: When matplotlib's minimum version is bumped to 3.8, this can be + # simplified since collection.get_offset_position no longer exists. offset_dict = {"data": "before", "screen": "after"} - offset_order = offset_dict[collection.get_offset_position()] + offset_order = ( + offset_dict[collection.get_offset_position()] + if hasattr(collection, "get_offset_position") + else "after" + ) self.renderer.draw_path_collection( paths=processed_paths, diff --git a/packages/python/plotly/test_requirements/requirements_37_optional.txt b/packages/python/plotly/test_requirements/requirements_37_optional.txt index 224fbf7db8b..173ecf501cb 100644 --- a/packages/python/plotly/test_requirements/requirements_37_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_37_optional.txt @@ -4,7 +4,7 @@ pandas==0.24.2 numpy==1.19.5 xarray==0.10.9 statsmodels==0.10.2 -pillow==5.2.0 +pillow==6.2.0 pytest==3.5.1 pytz==2016.10 ipython[all]==5.4.0 @@ -15,7 +15,7 @@ scipy==1.2.3 shapely==1.7.0 geopandas==0.3.0 pyshp==1.2.10 -matplotlib==2.2.3 +matplotlib==3.5.3 scikit-image==0.14.4 psutil==5.7.0 kaleido diff --git a/packages/python/plotly/test_requirements/requirements_38_optional.txt b/packages/python/plotly/test_requirements/requirements_38_optional.txt index 34b686ad024..e1c0c56b38d 100644 --- a/packages/python/plotly/test_requirements/requirements_38_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_38_optional.txt @@ -15,7 +15,7 @@ scipy==1.6.2 Shapely==1.7.1 geopandas==0.9.0 pyshp==2.1.3 -matplotlib==2.2.3 +matplotlib==3.7.3 scikit-image==0.18.1 psutil==5.7.0 kaleido diff --git a/packages/python/plotly/test_requirements/requirements_39_optional.txt b/packages/python/plotly/test_requirements/requirements_39_optional.txt index eae8cd6d2ec..3b950888ac6 100644 --- a/packages/python/plotly/test_requirements/requirements_39_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_39_optional.txt @@ -1,7 +1,7 @@ requests==2.25.1 tenacity==6.2.0 pandas==1.2.4 -numpy==1.20.2 +numpy==1.21.6 xarray==0.17.0 statsmodels Pillow==8.2.0 @@ -15,7 +15,7 @@ scipy==1.6.2 Shapely==1.7.1 geopandas==0.9.0 pyshp==2.1.3 -matplotlib==2.2.3 +matplotlib==3.8.0 scikit-image==0.18.1 psutil==5.7.0 kaleido diff --git a/packages/python/plotly/test_requirements/requirements_39_pandas_2_optional.txt b/packages/python/plotly/test_requirements/requirements_39_pandas_2_optional.txt index a36c1c53d04..48efa437f38 100644 --- a/packages/python/plotly/test_requirements/requirements_39_pandas_2_optional.txt +++ b/packages/python/plotly/test_requirements/requirements_39_pandas_2_optional.txt @@ -1,7 +1,7 @@ requests==2.25.1 tenacity==6.2.0 pandas==2.0.2 -numpy==1.20.3 +numpy==1.21.6 xarray==0.17.0 statsmodels Pillow==8.2.0 @@ -15,7 +15,7 @@ scipy==1.6.2 Shapely==1.7.1 geopandas==0.9.0 pyshp==2.1.3 -matplotlib==2.2.3 +matplotlib==3.8.0 scikit-image==0.18.1 psutil==5.7.0 kaleido