[Matplotlib-users] ValueError: Can only output finite numbers in PDF

Jouni K. Seppänen jks at iki.fi
Sun Nov 26 07:04:45 EST 2017


Neal Becker <ndbecker2 at gmail.com> writes:

> I can plot my semilogy plot fine to Qt5Agg backend, but switching to pdf 
> gave the error
> ValueError: Can only output finite numbers in PDF

This means the pdf backend has received infinite values, probably from
taking the logarithm of a nonpositive number. Somewhere in the chain
between semilogy and the pdf backend there should be logic that decides
what to do with those (e.g. clip to figure edge, or omit the point and
adjacent lines entirely).

In my copy of matplotlib 2.0.2 I don't see an error message from the
following code. Instead the negative value and adjacent lines are simply
missing.

    from matplotlib import pyplot as plt
    plt.semilogy([3,1,4,-1,5,9])
    plt.savefig('semilogy.pdf')

-- 
Jouni K. Seppänen
http://www.iki.fi/jks



More information about the Matplotlib-users mailing list