cedadev / jasmin_scivm

9 stars 0 forks source link

cf-plot broken for polar stereographic plots / basemap issue #182

Closed ajheaps closed 6 years ago

ajheaps commented 6 years ago

Matplotlib 2.2.2 and Basemap on jasmin no longer work well together and this affects the plotting of polar stereographic maps in particular in cf-plot.

https://stackoverflow.com/questions/50691151/axessubplot-object-has-no-attribute-get-axis-bgcolor describes the issue. Basically in Basemap ax.get_axis_bgcolor() needs to be replaced by ax.get_fc()

Test code to show the problem: from mpl_toolkits.basemap import Basemap m = Basemap() m.fillcontinents(color='coral',lake_color='aqua')

Error: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/site-packages/mpl_toolkits/basemap/init.py", line 1767, in fillcontinents axisbgc = ax.get_axis_bgcolor() AttributeError: 'AxesSubplot' object has no attribute 'get_axis_bgcolor'

Update of Basemap in the JAP required.

alaniwi commented 6 years ago

Somebody raised a similar matter at #181. Unfortunately it seems that there isn't a later version of basemap for us to upgrade to, and it has been deprecated (see https://www.scivision.co/cartopy-replace-deprecated-basemap/) so I don't know whether a fix will be issued, though if you become aware of one, then please let us know.

Regarding patching basemap locally to support current and future versions of matplotlib, I don't think that CEDA can support this because of the open-ended nature of this task, although it is technically possible to produce an RPM which contains a patch to the vendor source.

I think the proper solution is updating cf-plot to use cartopy in place of basemap.

As an interim solution pending this, it may be possible to monkey-patch matplotlib from within cfplot. I was able to get your test code working by inserting the following at the top:

import matplotlib.axes._base as _base
_base._AxesBase.get_axis_bgcolor = _base._AxesBase.get_fc

or it also works with a different local variable name for the module in place of _base if wanted (and my working example also has import matplotlib.pyplot as plt and plt.savefig('test.png') so that I can see some output).

This is obviously a bit messy, but it might buy you some time. You could of course make it dependent on matplotlib.__version__ and mpl_toolkits.basemap.Basemap.__version__ rather than doing it unconditionally.

Unfortunately I am going to close this issue as WONTFIX. Feel free to reopen it if you become aware of a vendor-patched version of basemap. If you produce a modified version of cf-plot which you would like us to package, please create a separate issue about that.

Tagging @bnlawrence here in case he radically disagrees with the above.

alaniwi commented 6 years ago

test

alaniwi commented 6 years ago

Reopening. I see a basemap 1.1.0 release on GitHub (at https://github.com/matplotlib/basemap/releases/) not listed in the downloads on SourceForge. I'll give it a go. But it is still over a year old, and the general comments about migrating to sourceforge still apply.

alaniwi commented 6 years ago

Okay, you're in luck. 1.1.0 does actually seem to fix the problem.

alaniwi commented 6 years ago

Now confirmed that the same update will fix also #181, so probably no further gain in tracking these separately. Re-closing ticket, this time as duplicate. I hope to get it installed soon.