Why am I getting a ValueError in matplotlib.pyplot ?. Here is my code:
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5,6])
f = 1.234
s = "number %i" % f
print s
plt.savefig(s)
so far so good. The figure is saved to a file with the name number 1 (the integer part of f) If however I do.
plt.plot([1,2,3,4,5,6])
f = 1.234
s = "number %.2f" % f
print s
plt.savefig(s)
The print statement prints 1.234 as expected whereas the plt.savefig(s) gives:
ValueError: Format "23" is not supported. Supported formats: eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff.
Somehow the savefig() method mixes the string formatting with the file format for saving. I am running python 2.7 with matplotlib 1.5.1
plt.savefig(s.replace('.',','))