Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
Bug summary
Calling get_extents on a BufferRegion returns the values as unsigned ints so if the region was outside of the canvas, they are incorrect.
The y-axis increases downwards.
Code for reproduction
importmatplotlib.pyplotaspltfrommatplotlib.transformsimportBboximportstructfig=plt.figure()canvas=fig.canvasw,h=canvas.get_width_height()br=canvas.copy_from_bbox(Bbox.from_extents(-10,h-1,10,h+1))ext=br.get_extents()print(ext,struct.unpack('iiii',struct.pack('IIII',*ext)))
Actual outcome
(4294967286, 4294967295, 10, 1) (-10, -1, 10, 1)
Expected outcome
(-10, -1, 10, 1)
Additional information
I think the problem comes from this:
https://github.com/matplotlib/matplotlib/blob/main/src/_backend_agg_wrapper.cpp#L77
static PyObject *PyBufferRegion_get_extents(PyBufferRegion *self, PyObject *args){ agg::rect_i rect = self->x->get_rect(); return Py_BuildValue("IIII", rect.x1, rect.y1, rect.x2, rect.y2);}
Replacing 'IIII' with 'iiii' would solve it
Operating system
Windows 10
Matplotlib Version
3.5.2
Matplotlib Backend
TkAgg
Python version
3.10.4
Jupyter version
No response
Installation
pip