Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16ae357

Browse files
authored
Merge pull request#17444 from anntzer/odddash
Support odd-length dash patterns in Agg.
2 parents0c0848b +98ff4b4 commit16ae357

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

‎lib/matplotlib/tests/test_lines.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,9 @@ def test_marker_as_markerstyle():
217217

218218
assert_array_equal(line2.get_marker().vertices,triangle1.vertices)
219219
assert_array_equal(line3.get_marker().vertices,triangle1.vertices)
220+
221+
222+
@check_figures_equal()
223+
deftest_odd_dashes(fig_test,fig_ref):
224+
fig_test.add_subplot().plot([1,2],dashes=[1,2,3])
225+
fig_ref.add_subplot().plot([1,2],dashes=[1,2,3,1,2,3])

‎src/py_converters.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ int convert_dashes(PyObject *dashobj, void *dashesp)
226226
PyObject *dash_offset_obj =NULL;
227227
double dash_offset =0.0;
228228
PyObject *dashes_seq =NULL;
229-
Py_ssize_t nentries;
230229

231230
if (!PyArg_ParseTuple(dashobj,"OO:dashes", &dash_offset_obj, &dashes_seq)) {
232231
return0;
@@ -256,18 +255,17 @@ int convert_dashes(PyObject *dashobj, void *dashesp)
256255
return0;
257256
}
258257

259-
nentries =PySequence_Size(dashes_seq);
260-
if (nentries %2 !=0) {
261-
PyErr_Format(PyExc_ValueError,"dashes sequence must have an even number of elements");
262-
return0;
263-
}
258+
Py_ssize_t nentries =PySequence_Size(dashes_seq);
259+
// If the dashpattern has odd length, iterate through it twice (in
260+
// accordance with the pdf/ps/svg specs).
261+
Py_ssize_t dash_pattern_length = (nentries %2) ?2 * nentries : nentries;
264262

265-
for (Py_ssize_t i =0; i <nentries; ++i) {
263+
for (Py_ssize_t i =0; i <dash_pattern_length; ++i) {
266264
PyObject *item;
267265
double length;
268266
double skip;
269267

270-
item =PySequence_GetItem(dashes_seq, i);
268+
item =PySequence_GetItem(dashes_seq, i % nentries);
271269
if (item ==NULL) {
272270
return0;
273271
}
@@ -280,7 +278,7 @@ int convert_dashes(PyObject *dashobj, void *dashesp)
280278

281279
++i;
282280

283-
item =PySequence_GetItem(dashes_seq, i);
281+
item =PySequence_GetItem(dashes_seq, i % nentries);
284282
if (item ==NULL) {
285283
return0;
286284
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp