Skip to content
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

Recent version of matplotlib won't plot with colorbar #1087

Open
cgadal opened this issue Jan 15, 2025 · 0 comments
Open

Recent version of matplotlib won't plot with colorbar #1087

cgadal opened this issue Jan 15, 2025 · 0 comments

Comments

@cgadal
Copy link

cgadal commented Jan 15, 2025

As mentioned in issue #1006 and #1009, trying to view a CellVariable using

viewer = MatplotlibViewer(vars=varname, datamin=-0, datamax=0, title="Grid2D test", axes=ax)

or

viewer = Viewer(vars=phi, datamin=-1, datamax=1.)

will result in

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.

See for example https://pages.nist.gov/fipy/en/latest/generated/examples.diffusion.circle.html#module-examples.diffusion.circle.

This is due to a change in recent versions of matplotlib where fig.colorbar will not guess anymore from which ax it will steal space. See for example matplotlib/matplotlib#23973.

Temporary fixes:

  • either roll back to matplotlib 5.1
  • use viewer without the colorbar as viewer = MatplotlibViewer(vars=phi, datamin=-0, datamax=0, title="Grid2D test", axes=ax, colorbar=None)

change in fipy code:

I am new to fipy, but I suspect that passing explicitly the ax in this part of the code would solve the problem:

if colorbar:
self._colorbar = self.fig.colorbar(mappable=self._mappable,
orientation=colorbar,
label=self.vars[0].name)

maybe as:

 if colorbar: 
     self._colorbar = self.fig.colorbar(mappable=self._mappable, 
                                        orientation=colorbar, 
                                        label=self.vars[0].name, 
                                        ax=self.axes) 

I have not tried yet tough.
Tried it and it works perfectly it seems. Will open a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant