proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.07k stars 96 forks source link

AttributeError: 'CartesianAxesSubplot' object has no attribute '_shared_x_axes' or '_shared_y_axes' #419

Closed PaleoLipidRR closed 1 year ago

PaleoLipidRR commented 1 year ago

Description

I just recently experience this issue when Proplot (v.0.9.7) started giving errors if I don't specify "share=False" in my first line fig, axs = plot.subplots()

It's okay if I only plot one subplot.

I run this on .ipynb on VS Studio.

Error Message

Output exceeds the [size limit](command:workbench.action.openSettings?%5B%22notebook.output.textLineLimit%22%5D). Open the full output data [in a text editor](command:workbench.action.openLargeOutput?fcd62dde-5462-407a-b403-167e7ff65e46)---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[6], line 1
----> 1 fig, axs = plot.subplots(ncols=2)

File [c:\Users\ratta\anaconda3_64bit\envs\proplot_visualizing\lib\site-packages\proplot\ui.py:192](file:///C:/Users/ratta/anaconda3_64bit/envs/proplot_visualizing/lib/site-packages/proplot/ui.py:192), in subplots(*args, **kwargs)
    190 # Initialize
    191 fig = figure(rc_kw=rc_kw, **kwargs)
--> 192 axs = fig.add_subplots(*args, **kwsubs)
    193 axs.format(rc_kw=rc_kw, **kwformat)
    194 return fig, axs

File [c:\Users\ratta\anaconda3_64bit\envs\proplot_visualizing\lib\site-packages\proplot\figure.py:1362](file:///C:/Users/ratta/anaconda3_64bit/envs/proplot_visualizing/lib/site-packages/proplot/figure.py:1362), in Figure.add_subplots(self, array, ncols, nrows, order, proj, projection, proj_kw, projection_kw, basemap, **kwargs)
   1360     ss = gs[y0:y1 + 1, x0:x1 + 1]
   1361     kw = {**kwargs, **axes_kw[num], 'number': num}
-> 1362     axs[idx] = self.add_subplot(ss, **kw)
   1364 self.format(**figure_kw)
   1365 return pgridspec.SubplotGrid(axs)

File [c:\Users\ratta\anaconda3_64bit\envs\proplot_visualizing\lib\site-packages\proplot\figure.py:1248](file:///C:/Users/ratta/anaconda3_64bit/envs/proplot_visualizing/lib/site-packages/proplot/figure.py:1248), in Figure.add_subplot(self, number, *args, **kwargs)
   1246 self._subplot_counter += 1  # unique label for each subplot
   1247 kwargs.setdefault('label', f'subplot_{self._subplot_counter}')
-> 1248 ax = super().add_subplot(ss, _subplot_spec=ss, **kwargs)
   1249 if number:
   1250     self._subplot_dict[number] = ax
...
--> 548 self._shared_y_axes.join(self, sharey)  # type: ignore # share limit/scale changes
    549 if sharey.yaxis.isDefault_majloc and not self.yaxis.isDefault_majloc:
    550     sharey.yaxis.set_major_locator(self.yaxis.get_major_locator())

AttributeError: 'CartesianAxesSubplot' object has no attribute '_shared_y_axes'

Equivalent steps in matplotlib

Please try to make sure this bug is related to a proplot-specific feature. If you're not sure, try to replicate it with the native matplotlib API. Matplotlib bugs belong on the matplotlib github page.


# Base libraries
import pandas as pd
import geopandas as gpd
import numpy as np
import xarray as xr
xr.set_options(file_cache_maxsize=10)

# Data science, Machine Learning, and Statistics
import scipy as scipy
from scipy import stats
from sklearn import linear_model, datasets
from sklearn import mixture
from sklearn.metrics import silhouette_samples, silhouette_score

from sklearn.linear_model import LinearRegression, RANSACRegressor, HuberRegressor, TheilSenRegressor

# Visualizations
import seaborn as sns
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.transforms as transforms
from matplotlib.patches import Rectangle
import proplot as plot 
import cartopy.crs as ccrs

# Plate reconstructions
# import shapefile as shp
from shapely.geometry import Point, Polygon
import shapely
from geopy.distance import distance, Distance, lonlat

# Miscellaneous
import string
import os
import requests
import io
from tqdm import tqdm
import time

### Proplot version

matplotlib version: 3.5.1
proplot version: 0.9.7
pandas version: 1.5.3
matplotlib version: 0.12.2
numpy version: 1.24.2
xarray version: 2023.3.0
lukelbd commented 1 year ago

This looks like a dependency issue: proplot 0.9.7 requires matplotlib < 3.5. Not sure how you got incompatible versions -- when I conda install proplot and pip install proplot in an empty environment I get matplotlib 3.4.3 (see below). Anyway pip install matplotlib==3.4.3 or conda install -c conda-forge matplotlib=3.4.3 should fix the issue.

$ pip install proplot
Collecting proplot
  Using cached proplot-0.9.7-py3-none-any.whl (8.0 MB)
Collecting matplotlib<3.5.0,>=3.3.0
  Using cached matplotlib-3.4.3-cp310-cp310-macosx_10_9_x86_64.whl
Requirement already satisfied: numpy>=1.16 in /Users/ldavis/mambaforge/envs/proplot-tmp/lib/python3.10/site-packages (from matplotlib<3.5.0,>=3.3.0->proplot) (1.24.2)
Requirement already satisfied: python-dateutil>=2.7 in /Users/ldavis/mambaforge/envs/proplot-tmp/lib/python3.10/site-packages (from matplotlib<3.5.0,>=3.3.0->proplot) (2.8.2)
Collecting kiwisolver>=1.0.1
  Downloading kiwisolver-1.4.4-cp310-cp310-macosx_10_9_x86_64.whl (65 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.5/65.5 kB 2.6 MB/s eta 0:00:00
Collecting cycler>=0.10
  Using cached cycler-0.11.0-py3-none-any.whl (6.4 kB)
Collecting pyparsing>=2.2.1
  Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
Collecting pillow>=6.2.0
  Downloading Pillow-9.5.0-cp310-cp310-macosx_10_10_x86_64.whl (3.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 21.5 MB/s eta 0:00:00
Requirement already satisfied: six>=1.5 in /Users/ldavis/mambaforge/envs/proplot-tmp/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib<3.5.0,>=3.3.0->proplot) (1.16.0)
Installing collected packages: pyparsing, pillow, kiwisolver, cycler, matplotlib, proplot
Successfully installed cycler-0.11.0 kiwisolver-1.4.4 matplotlib-3.4.3 pillow-9.5.0 proplot-0.9.7 pyparsing-3.0.9
PaleoLipidRR commented 1 year ago

This looks like a dependency issue: proplot 0.9.7 requires matplotlib < 3.5. Not sure how you got incompatible versions -- when I conda install proplot and pip install proplot in an empty environment I get matplotlib 3.4.3 (see below). Anyway pip install matplotlib==3.4.3 or conda install -c conda-forge matplotlib=3.4.3 should fix the issue.

$ pip install proplot
Collecting proplot
  Using cached proplot-0.9.7-py3-none-any.whl (8.0 MB)
Collecting matplotlib<3.5.0,>=3.3.0
  Using cached matplotlib-3.4.3-cp310-cp310-macosx_10_9_x86_64.whl
Requirement already satisfied: numpy>=1.16 in /Users/ldavis/mambaforge/envs/proplot-tmp/lib/python3.10/site-packages (from matplotlib<3.5.0,>=3.3.0->proplot) (1.24.2)
Requirement already satisfied: python-dateutil>=2.7 in /Users/ldavis/mambaforge/envs/proplot-tmp/lib/python3.10/site-packages (from matplotlib<3.5.0,>=3.3.0->proplot) (2.8.2)
Collecting kiwisolver>=1.0.1
  Downloading kiwisolver-1.4.4-cp310-cp310-macosx_10_9_x86_64.whl (65 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.5/65.5 kB 2.6 MB/s eta 0:00:00
Collecting cycler>=0.10
  Using cached cycler-0.11.0-py3-none-any.whl (6.4 kB)
Collecting pyparsing>=2.2.1
  Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
Collecting pillow>=6.2.0
  Downloading Pillow-9.5.0-cp310-cp310-macosx_10_10_x86_64.whl (3.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 21.5 MB/s eta 0:00:00
Requirement already satisfied: six>=1.5 in /Users/ldavis/mambaforge/envs/proplot-tmp/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib<3.5.0,>=3.3.0->proplot) (1.16.0)
Installing collected packages: pyparsing, pillow, kiwisolver, cycler, matplotlib, proplot
Successfully installed cycler-0.11.0 kiwisolver-1.4.4 matplotlib-3.4.3 pillow-9.5.0 proplot-0.9.7 pyparsing-3.0.9

Thank you! I created a new environment and do "conda install" with "conda-forge" as my default channel. I am not sure why my matplotlib got installed with the incompatible version. Anyway, thank you so much!