Skip to content

Commit 5da2d9d

Browse files
committed
Merge remote-tracking branch 'upstream/v1.2.x'
2 parents 39384a5 + 293d42b commit 5da2d9d

File tree

12 files changed

+233
-87
lines changed

12 files changed

+233
-87
lines changed

examples/animation/old_animation/draggable_legend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
2222

23-
fn = get_sample_data("lena.png", asfileobj=False)
24-
arr_lena = read_png(fn)
23+
fn = get_sample_data("ada.png", asfileobj=False)
24+
arr_ada = read_png(fn)
2525

26-
imagebox = OffsetImage(arr_lena, zoom=0.2)
26+
imagebox = OffsetImage(arr_ada, zoom=0.2)
2727

2828
ab = AnnotationBbox(imagebox, xy,
2929
xybox=(120., -80.),

examples/misc/sample_data_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import print_function
66
import matplotlib.cbook as cbook
77
import matplotlib.pyplot as plt
8-
fname = cbook.get_sample_data('lena.png', asfileobj=False)
8+
fname = cbook.get_sample_data('ada.png', asfileobj=False)
99

1010
print('fname', fname)
1111
im = plt.imread(fname)

examples/pylab_examples/demo_annotation_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070

7171
from matplotlib._png import read_png
72-
fn = get_sample_data("lena.png", asfileobj=False)
72+
fn = get_sample_data("grace_hopper.png", asfileobj=False)
7373
arr_lena = read_png(fn)
7474

7575
imagebox = OffsetImage(arr_lena, zoom=0.2)

examples/pylab_examples/demo_text_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def draw(self, renderer=None):
6363
ax = plt.subplot(211)
6464

6565
from matplotlib._png import read_png
66-
fn = get_sample_data("lena.png", asfileobj=False)
66+
fn = get_sample_data("grace_hopper.png", asfileobj=False)
6767
arr = read_png(fn)
6868

6969
text_path = TextPath((0, 0), "!?", size=150)

examples/pylab_examples/image_demo3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import matplotlib.cbook as cbook
99

10-
datafile = cbook.get_sample_data('lena.jpg')
10+
datafile = cbook.get_sample_data('grace_hopper.jpg')
1111
lena = Image.open(datafile)
1212
dpi = rcParams['figure.dpi']
1313
figsize = lena.size[0]/dpi, lena.size[1]/dpi
301 KB
Loading
59.9 KB
Loading
614 KB
Loading

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ def get_rotate_label(self, text):
161161

162162
def _get_coord_info(self, renderer):
163163
minx, maxx, miny, maxy, minz, maxz = self.axes.get_w_lims()
164+
if minx > maxx:
165+
minx, maxx = maxx, minx
166+
if miny > maxy:
167+
miny, maxy = maxy, miny
168+
if minz > maxz:
169+
minz, maxz = maxz, minz
164170
mins = np.array((minx, miny, minz))
165171
maxs = np.array((maxx, maxy, maxz))
166172
centers = (maxs + mins) / 2.
@@ -205,9 +211,13 @@ def draw(self, renderer):
205211
index = info['i']
206212

207213
# filter locations here so that no extra grid lines are drawn
208-
interval = self.get_view_interval()
209-
majorLocs = [loc for loc in majorLocs if \
210-
interval[0] <= loc <= interval[1]]
214+
locmin, locmax = self.get_view_interval()
215+
if locmin > locmax:
216+
locmin, locmax = locmax, locmin
217+
218+
# Rudimentary clipping
219+
majorLocs = [loc for loc in majorLocs if
220+
locmin <= loc <= locmax]
211221
self.major.formatter.set_locs(majorLocs)
212222
majorLabels = [self.major.formatter(val, i)
213223
for i, val in enumerate(majorLocs)]

src/_backend_agg.cpp

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include "numpy/arrayobject.h"
4141
#include "agg_py_transforms.h"
42+
#include "file_compat.h"
4243

4344
#ifndef M_PI
4445
#define M_PI 3.14159265358979323846
@@ -2028,44 +2029,42 @@ RendererAgg::write_rgba(const Py::Tuple& args)
20282029

20292030
FILE *fp = NULL;
20302031
Py::Object py_fileobj = Py::Object(args[0]);
2031-
2032-
#if PY3K
2033-
int fd = PyObject_AsFileDescriptor(py_fileobj.ptr());
2034-
PyErr_Clear();
2035-
#endif
2032+
PyObject* py_file = NULL;
2033+
bool close_file = false;
20362034

20372035
if (py_fileobj.isString())
20382036
{
2039-
std::string fileName = Py::String(py_fileobj);
2040-
const char *file_name = fileName.c_str();
2041-
if ((fp = fopen(file_name, "wb")) == NULL)
2042-
throw Py::RuntimeError(
2043-
Printf("Could not open file %s", file_name).str());
2044-
if (fwrite(pixBuffer, 1, NUMBYTES, fp) != NUMBYTES)
2045-
{
2046-
fclose(fp);
2047-
throw Py::RuntimeError(
2048-
Printf("Error writing to file %s", file_name).str());
2037+
if ((py_file = npy_PyFile_OpenFile(py_fileobj.ptr(), (char *)"wb")) == NULL) {
2038+
throw Py::Exception();
20492039
}
2040+
close_file = true;
20502041
}
2051-
#if PY3K
2052-
else if (fd != -1)
2042+
else
20532043
{
2054-
if (write(fd, pixBuffer, NUMBYTES) != (ssize_t)NUMBYTES)
2055-
{
2056-
throw Py::RuntimeError("Error writing to file");
2057-
}
2044+
py_file = py_fileobj.ptr();
20582045
}
2059-
#else
2060-
else if (PyFile_CheckExact(py_fileobj.ptr()))
2046+
2047+
if ((fp = npy_PyFile_Dup(py_file, (char *)"wb")))
20612048
{
2062-
fp = PyFile_AsFile(py_fileobj.ptr());
20632049
if (fwrite(pixBuffer, 1, NUMBYTES, fp) != NUMBYTES)
20642050
{
2051+
npy_PyFile_DupClose(py_file, fp);
2052+
2053+
if (close_file) {
2054+
npy_PyFile_CloseFile(py_file);
2055+
Py_DECREF(py_file);
2056+
}
2057+
20652058
throw Py::RuntimeError("Error writing to file");
20662059
}
2060+
2061+
npy_PyFile_DupClose(py_file, fp);
2062+
2063+
if (close_file) {
2064+
npy_PyFile_CloseFile(py_file);
2065+
Py_DECREF(py_file);
2066+
}
20672067
}
2068-
#endif
20692068
else
20702069
{
20712070
PyObject* write_method = PyObject_GetAttrString(py_fileobj.ptr(),

0 commit comments

Comments
 (0)