8000 Support URLs on QuadMesh in SVGs. · QuLogic/matplotlib@82a91c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 82a91c5

Browse files
committed
Support URLs on QuadMesh in SVGs.
Fixes matplotlib#12392.
1 parent eecad37 commit 82a91c5

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

lib/matplotlib/backend_bases.py

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

240240
def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
241241
coordinates, offsets, offsetTrans, facecolors,
242-
antialiased, edgecolors):
242+
antialiased, edgecolors, urls=None):
243243
"""
244244
Fallback implementation of :meth:`draw_quad_mesh` that generates paths
245245
and then calls :meth:`draw_path_collection`.
@@ -252,10 +252,14 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
252252
if edgecolors is None:
253253
edgecolors = facecolors
254254
linewidths = np.array([gc.get_linewidth()], float)
255+
if urls is None:
256+
urls = [None]
257+
else:
258+
urls = list(cbook.flatten(urls))
255259

256260
return self.draw_path_collection(
257261
gc, master_transform, paths, [], offsets, offsetTrans, facecolors,
258-
edgecolors, linewidths, [], [antialiased], [None], 'screen')
262+
edgecolors, linewidths, [], [antialiased], urls, 'screen')
259263

260264
def draw_gouraud_triangle(self, gc, points, colors, transform):
261265
"""

lib/matplotlib/collections.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,8 @@ def draw(self, renderer):
20482048
coordinates, offsets, transOffset,
20492049
# Backends expect flattened rgba arrays (n*m, 4) for fc and ec
20502050
self.get_facecolor().reshape((-1, 4)),
2051-
self._antialiased, self.get_edgecolors().reshape((-1, 4)))
2051+
self._antialiased, self.get_edgecolors().reshape((-1, 4)),
2052+
urls=self.get_urls())
20522053
gc.restore()
20532054
renderer.close_group(self.__class__.__name__)
20542055
self.stale = False

lib/matplotlib/tests/test_backend_svg.py

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

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

238253

0 commit comments

Comments
 (0)
0