danjgale / surfplot

A package for publication-ready brain surface figures
https://surfplot.readthedocs.io/en/latest/
Other
50 stars 13 forks source link

Failure with matplotlib 3.6.0 prereleases #16

Closed mgxd closed 1 year ago

mgxd commented 1 year ago

This came up while prerelease testing - was able to reproduce with the included example:

Traceback (most recent call last):
  File "/Users/mathiasg/code/surfplot/tutorials/examples/plot_example_01.py", line 40, in <module>
    fig = p.build(cbar_kws=cbar_kws)
  File "/Users/mathiasg/.pyenv/versions/nipreps/lib/python3.10/site-packages/surfplot/plotting.py", line 510, in build
    self._add_colorbars(**cbar_kws)
  File "/Users/mathiasg/.pyenv/versions/nipreps/lib/python3.10/site-packages/surfplot/plotting.py", line 451, in _add_colorbars
    cb = plt.colorbar(sm, ticks=ticks, location=location, 
  File "/Users/mathiasg/.pyenv/versions/nipreps/lib/python3.10/site-packages/matplotlib/pyplot.py", line 2053, in colorbar
    ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kwargs)
  File "/Users/mathiasg/.pyenv/versions/nipreps/lib/python3.10/site-packages/matplotlib/figure.py", line 1256, in colorbar
    raise ValueError(
ValueError: Unable to determine Axes to steal space for Colorbar. Either provide the *cax* argument to use as the Axes for the Colorbar, provide the *ax* argument to steal space from it, or add *mappable* to an Axes.

relevant versions:

brainspace==0.1.4 matplotlib==3.6.0rc2 vtk==9.2.0rc2

emdupre commented 1 year ago

Just to +1 this -- I hit the same issue in my own environment with MPL 3.6.0 installed. Now that this is an official MPL release, I imagine quite a few other folks might also benefit from the fix !

Thanks as always for surfplot, @danjgale !

danjgale commented 1 year ago

Hi @mgxd, thanks for this issue and I will get to review + pulling your PR shortly. Totally swamped at moment, but hoping to have more time in the coming weeks. @emdupre Good to know, I will make this a priority

danjgale commented 1 year ago

@mgxd and @emdupre this has been merged to main now. Thank you so much for you contribution and your patience!

danjgale commented 1 year ago

I may have spoken too soon, as I can no longer get it working with 3.6.0; the same error still occurs. However, it works with as expected with 3.6.2. Edit: Nevermind, silly error on my part. Works.

emdupre commented 1 year ago

Thank you, @danjgale !!