pyresample
pyresample copied to clipboard
MatplotlibDeprecationWarning in plotting tests
Code Sample, a minimal, complete, and verifiable piece of code
# Your code here
python -m unittest pyresample.test.test_plot.Test.test_plate_carreeplot
Problem description
As discussed with @djhoese
The problem in the test is that we are recreating the axes inside the quicklook code multiple times and matplotlib can't tell the difference. I think we could (should?) allow the user to pass an ax argument to the quicklook function that will be drawn to. That way, the test could either reuse the same ax for the 3 different quicklook calls it makes or create a new one if needed.
This ax could let users add multiple quicklooks to one figure which would be nice
Currently the user function show_quicklook doesn't return anything.
Expected Output
The unittests should not shout out about any warnings.
Actual Result, Traceback if applicable
...plot.py:259: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
ax = plt.axes(projection=ccrs)
Versions of Python, package at hand and relevant dependencies
Matplotlib 3.1.1
Cartopy 0.17.0
Python 3.7.3
Latest Pyresample master branch: pyresample-1.12.3+214.g19ff793.tar.gz
The reason I asked about the return value of the quicklook code was I was wondering if it could return the newly created ax object. It depends if this is a utility function (it probably should be) that a user incorporates in to there overall plotting code or whether this is an all-in-one function that the user calls once and sees an image. The former is more flexible and would work really well in an xarray accessor for pyresample 2.0 by doing my_data_arr.pyresample.plot_quicklook(...).
@djhoese I agree with you. But the code was originally and still is "an all-in-one function that the user calls once and sees an image". I just preserved that behaviour and changed a bit to make it easier to make unittests
Ok, I'm fine with that. Then this test that calls the quicklook function 3 times should be split in to 3 separate tests to avoid this warning.