Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b751318

Browse files
committed
Fix saving to a file-like object.
svn path=/trunk/matplotlib/; revision=4651
1 parent 62b9e02 commit b751318

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

lib/matplotlib/cbook.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def is_string_like(obj):
214214
return 1
215215

216216
def is_writable_file_like(obj):
217-
return hasattr(filename, 'write') and callable(filename.write)
217+
return hasattr(obj, 'write') and callable(obj.write)
218218

219219
def is_scalar(obj):
220220
return is_string_like(obj) or not iterable(obj)
@@ -891,7 +891,7 @@ def xy(self, i0=0, isub=1):
891891
return x, self._mem[i0:self._n:isub]
892892

893893
def plot(self, i0=0, isub=1, fig=None):
894-
if fig is None:
894+
if fig is None:
895895
from pylab import figure, show
896896
fig = figure()
897897

src/_backend_agg.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,11 +2293,9 @@ RendererAgg::write_png(const Py::Tuple& args)
22932293
throw Py::RuntimeError( Printf("Could not open file %s", file_name).str() );
22942294
}
22952295
else {
2296-
if ((fp = PyFile_AsFile(py_fileobj.ptr())) == NULL) {
2297-
PyObject* write_method = PyObject_GetAttrString(py_fileobj.ptr(), "write");
2298-
if (!(write_method && PyCallable_Check(write_method)))
2299-
throw Py::TypeError("Object does not appear to be a path or a Python file-like object");
2300-
}
2296+
PyObject* write_method = PyObject_GetAttrString(py_fileobj.ptr(), "write");
2297+
if (!(write_method && PyCallable_Check(write_method)))
2298+
throw Py::TypeError("Object does not appear to be a path or a Python file-like object");
23012299
}
23022300

23032301
png_bytep *row_pointers = NULL;

0 commit comments

Comments
 (0)