Skip to content

Commit a093342

Browse files
authored
Merge pull request matplotlib#22417 from anntzer/rgbafacearray
Support passing rgbaFace as an array to agg's draw_path.
2 parents 81e9559 + 9e05794 commit a093342

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

lib/matplotlib/tests/test_agg.py

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

88

99
from matplotlib import (
10-
collections, path, pyplot as plt, transforms as mtransforms, rcParams)
10+
collections, path, patheffects, pyplot as plt, transforms as mtransforms,
11+
rcParams)
1112
from matplotlib.backends.backend_agg import RendererAgg
1213
from matplotlib.figure import Figure
1314
from matplotlib.image import imread
@@ -349,3 +350,11 @@ def test_chunksize_toobig_chunks(chunk_limit_setup):
349350
rcParams['agg.path.chunksize'] = 90_000
350351
with pytest.raises(OverflowError, match='Please reduce'):
351352
ra.draw_path(gc, p, idt)
353+
354+
355+
def test_non_tuple_rgbaface():
356+
# This passes rgbaFace as a ndarray to draw_path.
357+
fig = plt.figure()
358+
fig.add_subplot(projection="3d").scatter(
359+
[0, 1, 2], [0, 1, 2], path_effects=[patheffects.Stroke(linewidth=4)])
360+
fig.canvas.draw()

src/py_converters.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,28 @@ int convert_rect(PyObject *rectobj, void *rectp)
191191
int convert_rgba(PyObject *rgbaobj, void *rgbap)
192192
{
193193
agg::rgba *rgba = (agg::rgba *)rgbap;
194-
194+
PyObject *rgbatuple = NULL;
195+
int success = 1;
195196
if (rgbaobj == NULL || rgbaobj == Py_None) {
196197
rgba->r = 0.0;
197198
rgba->g = 0.0;
198199
rgba->b = 0.0;
199200
rgba->a = 0.0;
200201
} else {
202+
if (!(rgbatuple = PySequence_Tuple(rgbaobj))) {
203+
success = 0;
204+
goto exit;
205+
}
201206
rgba->a = 1.0;
202207
if (!PyArg_ParseTuple(
203-
rgbaobj, "ddd|d:rgba", &(rgba->r), &(rgba->g), &(rgba->b), &(rgba->a))) {
204-
return 0;
208+
rgbatuple, "ddd|d:rgba", &(rgba->r), &(rgba->g), &(rgba->b), &(rgba->a))) {
209+
success = 0;
210+
goto exit;
205211
}
206212
}
207-
208-
return 1;
213+
exit:
214+
Py_XDECREF(rgbatuple);
215+
return success;
209216
}
210217

211218
int convert_dashes(PyObject *dashobj, void *dashesp)

0 commit comments

Comments
 (0)