proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.11k stars 102 forks source link

TypeError: ufunc 'isfinite' not supported for the input types #393

Closed lkugler closed 2 years ago

lkugler commented 2 years ago

Description

I want to warn others that this combination of Matplotlib + proplot + pandas doesnt work.

Steps to reproduce

import numpy as np
import datetime as dt
import pandas as pd
import matplotlib as mpl
mpl.use('agg')
import matplotlib.pyplot as plt
import proplot as pplt

fig, ax = pplt.subplots()   # <-------------------------  pplt instead plt

df = pd.DataFrame(index=pd.date_range(start=dt.datetime(2000,1,1), end=dt.datetime(2000,1,1, 2), freq='1H'),
                    data=dict(test=np.array([1.,2.,3.])))
df.plot(ax=ax)

Produces

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''

Equivalent (working) steps in matplotlib

import numpy as np
import datetime as dt
import pandas as pd
import matplotlib as mpl
mpl.use('agg')
import matplotlib.pyplot as plt

fig, ax = plt.subplots() 

df = pd.DataFrame(index=pd.date_range(start=dt.datetime(2000,1,1), end=dt.datetime(2000,1,1, 2), freq='1H'),
                    data=dict(test=np.array([1.,2.,3.])))
df.plot(ax=ax)

Proplot version

Matplotlib version 3.4.3 (same for 3.5.3) proplot 0.9.5 Pandas 1.3.4

lkugler commented 2 years ago

Same error in this example + solution with np.datetime64

Steps to reproduce

import numpy as np
import datetime as dt
import pandas as pd
import matplotlib as mpl
mpl.use('agg')
import matplotlib.pyplot as plt
import proplot as pplt

fig, ax = pplt.subplots()  
init = dt.datetime(2000, 1, 1)
ax.plot(init, 0, marker='>')  

Produces

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''

Equivalent working steps

fig, ax = pplt.subplots()  
init = np.datetime64(dt.datetime(2000, 1, 1))  # <------ add np.datetime64
ax.plot(init, 0, marker='>')  

Proplot version

Matplotlib version 3.4.3 proplot 0.9.5 Pandas 1.3.4

lkugler commented 2 years ago

Converting the input to np.datetime64 should not be necessary, as it is not required with default matplotlib, right?

lkugler commented 2 years ago

Solution: Install newest (dev) version

Version 0.9.5.post332 pip install git+https://github.com/proplot-dev/proplot.git

lukelbd commented 1 year ago

The latest stable proplot version 0.9.7 finally addresses this issue (#309). Just adds matplotlib / numpy dependency fixes to version 0.9.5 -- have yet to merge other master branch improvements.

julian-belina commented 1 year ago

I have just updated proplot to version 0.9.7 from conda forge but the error remains, unfortunately.

lukelbd commented 1 year ago

Oh you're right, sorry. Lumped this in with a bunch of other proplot version issue threads I was reviewing. Seems this is actually related to #320 (which was fixed on master).