Skip to content

MatplotlibDeprecationWarning from ax.spines[label].set_smart_bounds() #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jGaboardi opened this issue Oct 5, 2020 · 6 comments
Closed
Labels
bug level: expert priority: high needs to be resolved soon

Comments

@jGaboardi
Copy link
Member

Getting the following MatplotlibDeprecationWarning from here:

/Users/user/miniconda3/envs/env/lib/python3.8/site-packages/splot/_viz_esda_mpl.py:47: MatplotlibDeprecationWarning: 
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
  ax.spines['left'].set_smart_bounds(True)
/Users/user/miniconda3/envs/env/lib/python3.8/site-packages/splot/_viz_esda_mpl.py:48: MatplotlibDeprecationWarning: 
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
  ax.spines['bottom'].set_smart_bounds(True)

System Info:

CPython 3.8.5
IPython 7.18.1

compiler   : Clang 10.0.1 
system     : Darwin
release    : 19.6.0
machine    : x86_64
processor  : i386
CPU cores  : 8
interpreter: 64bit

Package Info:

esda                2.3.1
libpysal            4.3.0
matplotlib          3.3.2
numpy               1.19.1
scipy               1.5.2
splot               1.1.3
@martinfleis
Copy link
Member

Just ran into this. It seems that this will be removed in Matplotlib 3.4, which is the next minor release, so would be good to look into this before the next release of splot. Some relevant discussion here matplotlib/matplotlib#15417

@martinfleis martinfleis added priority: high needs to be resolved soon and removed priority: low labels Nov 22, 2020
@slumnitz
Copy link
Member

slumnitz commented Jan 11, 2021

It might be worth discussing whether this feature should be replaced or dropped. What do you think @martinfleis @ljwolf @darribas @sjsrey @weikang9009 @jGaboardi?

  • Currently set_smart_bounds() is not used as a default, as aspect_equal=True is the default and does not rely on smart bounds.
  • I think set_smart_bounds() is only of value when zstandard = False, aspect_equal=False, and the data range is far away from 0. I wonder though how often is the case that users would need that?

-> My recommendation would be to remove and not replace it. In case there are plot's that require this functionality due to very specific data ranges and users inform us about strange spines, we can include it again later.

This compares the (sensible) defaults with a disabled zstandard, no set_smart_bounds, and disabled aspect_equal:

image

@martinfleis
Copy link
Member

My recommendation would be to remove and not replace it

I am fine with that.

@jGaboardi
Copy link
Member Author

@slumnitz @martinfleis @sjsrey

ax.spines[<>].set_smart_bounds(<>) is now deprecated in matplotlib (v3.4.2), so we'll need to cut a release of splot ASAP that that incorporates #125.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-17-f759e0244905> in <module>
      1 fig, ax = matplotlib.pyplot.subplots(figsize=figsize)
----> 2 moran_scatterplot(moran_ntwwn, aspect_equal=False, ax=ax, **pltkwds);

~/miniconda3/envs/py39_spgh_dev/lib/python3.9/site-packages/splot/_viz_esda_mpl.py in moran_scatterplot(moran, zstandard, p, aspect_equal, ax, scatter_kwds, fitline_kwds)
    132             warnings.warn('`p` is only used for plotting `esda.moran.Moran_Local`\n'
    133                           'or `Moran_Local_BV` objects')
--> 134         fig, ax = _moran_global_scatterplot(moran=moran, zstandard=zstandard,
    135                                             ax=ax, aspect_equal=aspect_equal,
    136                                             scatter_kwds=scatter_kwds,

~/miniconda3/envs/py39_spgh_dev/lib/python3.9/site-packages/splot/_viz_esda_mpl.py in _moran_global_scatterplot(moran, zstandard, aspect_equal, ax, scatter_kwds, fitline_kwds)
    242 
    243     # get fig and ax
--> 244     fig, ax = _create_moran_fig_ax(ax, figsize=(7, 7),
    245                                    aspect_equal=aspect_equal)
    246 

~/miniconda3/envs/py39_spgh_dev/lib/python3.9/site-packages/splot/_viz_esda_mpl.py in _create_moran_fig_ax(ax, figsize, aspect_equal)
     45         ax.set_aspect('equal')
     46     else:
---> 47         ax.spines['left'].set_smart_bounds(True)
     48         ax.spines['bottom'].set_smart_bounds(True)
     49     return fig, ax

AttributeError: 'Spine' object has no attribute 'set_smart_bounds'

@martinfleis
Copy link
Member

It is just a matter of a release, right? I'll make a quick PR for #130 at some point today and we can release.

@jGaboardi
Copy link
Member Author

Yes, I believe so. The only place where set_smart_bounds was used was in _viz_esda_mpl.py._create_moran_fig_ax(), and that was removed.

@slumnitz would you be good for a release after Martin's PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug level: expert priority: high needs to be resolved soon
Projects
None yet
Development

No branches or pull requests

3 participants