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

Skip to content

Commit 9adb6ef

Browse files
committed
Support URLs on QuadMesh in SVGs.
Fixes #12392.
1 parent 302ca01 commit 9adb6ef

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
242242

243243
def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
244244
coordinates, offsets, offsetTrans, facecolors,
245-
antialiased, edgecolors):
245+
antialiased, edgecolors, urls=None):
246246
"""
247247
Fallback implementation of :meth:`draw_quad_mesh` that generates paths
248248
and then calls :meth:`draw_path_collection`.
@@ -255,10 +255,14 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
255255
if edgecolors is None:
256256
edgecolors = facecolors
257257
linewidths = np.array([gc.get_linewidth()], float)
258+
if urls is None:
259+
urls = [None]
260+
else:
261+
urls = list(cbook.flatten(urls))
258262

259263
return self.draw_path_collection(
260264
gc, master_transform, paths, [], offsets, offsetTrans, facecolors,
261-
edgecolors, linewidths, [], [antialiased], [None], 'screen')
265+
edgecolors, linewidths, [], [antialiased], urls, 'screen')
262266

263267
def draw_gouraud_triangle(self, gc, points, colors, transform):
264268
"""

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,7 @@ def draw(self, renderer):
20452045
renderer.draw_quad_mesh(
20462046
gc, transform.frozen(), self._meshWidth, self._meshHeight,
20472047
coordinates, offsets, transOffset, self.get_facecolor(),
2048-
self._antialiased, self.get_edgecolors())
2048+
self._antialiased, self.get_edgecolors(), urls=self.get_urls())
20492049
gc.restore()
20502050
renderer.close_group(self.__class__.__name__)
20512051
self.stale = False

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,25 @@ def test_url():
228228
p, = plt.plot([1, 3], [6, 5])
229229
p.set_url('http://example.com/baz')
230230

231+
# QuadMesh
232+
data = np.array([
233+
[np.nan, 4, np.nan],
234+
[2, 7, 5],
235+
[np.nan, 8, np.nan]
236+
])
237+
links = np.array([
238+
[np.nan, 'http://example.com/qux', np.nan],
239+
['http://example.com/quux', 'http://example.com/quuz',
240+
'http://example.com/corge'],
241+
[np.nan, 'http://example.com/grault', np.nan]
242+
])
243+
ax.pcolormesh(data, urls=links)
244+
231245
b = BytesIO()
232246
fig.savefig(b, format='svg')
233247
b = b.getvalue()
234-
for v in [b'foo', b'bar', b'baz']:
248+
for v in [b'foo', b'bar', b'baz', b'qux', b'quux', b'quuz', b'corge',
249+
b'grault']:
235250
assert b'http://example.com/' + v in b
236251

237252

0 commit comments

Comments
 (0)