proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics

Home Page:https://proplot.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trying to make a line over contourf returns TypeError

rvalenzuelar opened this issue · comments

I need to plot a contourf and overlay a line on it. If I try this with proplot I get the following error:

File [~/micromamba/envs/py_env/lib/python3.10/site-packages/proplot/internals/process.py:284](https://file+.vscode-resource.vscode-cdn.net/Users/raulvalenzuela/Library/CloudStorage/Dropbox/PythonProjects/Paper_ZAR_ROS/notebooks/~/micromamba/envs/py_env/lib/python3.10/site-packages/proplot/internals/process.py:284), in _preprocess_args.<locals>.decorator.<locals>._redirect_or_standardize(self, *args, **kwargs)
    281             ureg.setup_matplotlib(True)
    283 # Call main function
--> 284 return func(self, *args, **kwargs)

File [~/micromamba/envs/py_env/lib/python3.10/site-packages/proplot/axes/plot.py:2879](https://file+.vscode-resource.vscode-cdn.net/Users/raulvalenzuela/Library/CloudStorage/Dropbox/PythonProjects/Paper_ZAR_ROS/notebooks/~/micromamba/envs/py_env/lib/python3.10/site-packages/proplot/axes/plot.py:2879), in PlotAxes.plot(self, *args, **kwargs)
   2875 """
   2876 %(plot.plot)s
   2877 """
   2878 kwargs = _parse_vert(default_vert=True, **kwargs)
-> 2879 return self._apply_plot(*args, **kwargs)

File [~/micromamba/envs/py_env/lib/python3.10/site-packages/proplot/axes/plot.py:2853](https://file+.vscode-resource.vscode-cdn.net/Users/raulvalenzuela/Library/CloudStorage/Dropbox/PythonProjects/Paper_ZAR_ROS/notebooks/~/micromamba/envs/py_env/lib/python3.10/site-packages/proplot/axes/plot.py:2853), in PlotAxes._apply_plot(self, vert, *pairs, **kwargs)
   2850         objs.append((*eb, *es, obj) if eb or es else obj)
   2852 # Add sticky edges
-> 2853 self._add_sticky_edges(objs, 'x' if vert else 'y', xsides, only=mlines.Line2D)
   2854 self._update_guide(objs, **guide_kw)
   2855 return cbook.silent_list('Line2D', objs)
...
   2361 # masked_invalid previously never returned nomask as a mask and doing so
   2362 # threw off matplotlib (gh-22842).  So use shrink=False:
   2363 if res._mask is nomask:

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

With matplotlib runs ok.

Steps to reproduce

import proplot as pplt
import numpy as np
from datetime import datetime 

fig, ax = pplt.subplots()

x=[datetime(2023,1,1,1), datetime(2023,1,1,2), datetime(2023,1,1,3)]
y=range(125)
Z=np.random.rand(125,3)
ax.contourf(x,y,Z)
ax.plot([datetime(2023,1,1,2), datetime(2023,1,1,2)],[0,100])

Expected behavior:
Draw contour filled and line.

Actual behavior:
Throw TypeError described above.

Equivalent steps in matplotlib

import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime 

fig, ax = plt.subplots()

x=[datetime(2023,1,1,1), datetime(2023,1,1,2), datetime(2023,1,1,3)]
y=range(125)
Z=np.random.rand(125,3)
ax.contourf(x,y,Z)
ax.plot([datetime(2023,1,1,2), datetime(2023,1,1,2)],[0,100])

Proplot version

'0.9.7'

Cannot reproduce this issue on my end:
image

Hi @cvanelteren ! Could you confirm you are using the following versions?:

proplot: '0.9.7'
numpy: '1.24.3'
matplotlib: '3.4.3'

This was some time ago, but currently I am proplot 0.9.5. The env you listed produces the same error.

Ah for me it was related to cartopy, removing it runs the code above fine on the listed versions.

Thanks! I will have to figure it out then because cartopy is within the libs I use frequently.