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

Support url on QuadMesh in svg#17514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
QuLogic wants to merge5 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromQuLogic:svg-url-quadmesh
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletionslib/matplotlib/axis.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -316,6 +316,17 @@ def set_label2(self, s):
self.label2.set_text(s)
self.stale = True

def set_url(self, s):
"""
Set the url of label1 and label2

ACCEPTS: str
"""
super().set_url(s)
self.label1.set_url(s)
self.label2.set_url(s)
self.stale = True

def _set_artist_props(self, a):
a.set_figure(self.figure)

Expand Down
8 changes: 6 additions & 2 deletionslib/matplotlib/backend_bases.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -239,7 +239,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,

def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
coordinates, offsets, offsetTrans, facecolors,
antialiased, edgecolors):
antialiased, edgecolors, urls=None):
"""
Fallback implementation of :meth:`draw_quad_mesh` that generates paths
and then calls :meth:`draw_path_collection`.
Expand All@@ -252,10 +252,14 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
if edgecolors is None:
edgecolors = facecolors
linewidths = np.array([gc.get_linewidth()], float)
if urls is None:
urls = [None]
else:
urls = list(cbook.flatten(urls))

return self.draw_path_collection(
gc, master_transform, paths, [], offsets, offsetTrans, facecolors,
edgecolors, linewidths, [], [antialiased],[None], 'screen')
edgecolors, linewidths, [], [antialiased],urls, 'screen')

def draw_gouraud_triangle(self, gc, points, colors, transform):
"""
Expand Down
38 changes: 32 additions & 6 deletionslib/matplotlib/collections.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
line segments).
"""

import inspect
import math
from numbers import Number
import numpy as np
Expand DownExpand Up@@ -2043,12 +2044,37 @@ def draw(self, renderer):
renderer.draw_gouraud_triangles(
gc, triangles, colors, transform.frozen())
else:
renderer.draw_quad_mesh(
gc, transform.frozen(), self._meshWidth, self._meshHeight,
coordinates, offsets, transOffset,
# Backends expect flattened rgba arrays (n*m, 4) for fc and ec
self.get_facecolor().reshape((-1, 4)),
self._antialiased, self.get_edgecolors().reshape((-1, 4)))
try:
sig = inspect.signature(renderer.draw_quad_mesh)
except ValueError:
# Compiled backends like Agg don't have a signature, but also
# don't support urls anyway.
use_urls = False
else:
use_urls = 'urls' in sig.parameters
if use_urls:
renderer.draw_quad_mesh(
gc, transform.frozen(), self._meshWidth, self._meshHeight,
coordinates, offsets, transOffset, self.get_facecolor(),
self._antialiased, self.get_edgecolors(),
urls=self.get_urls())
renderer.draw_quad_mesh(
gc, transform.frozen(), self._meshWidth, self._meshHeight,
coordinates, offsets, transOffset,
# Backends expect flattened rgba arrays (n*m, 4) for fc
# and ec
self.get_facecolor().reshape((-1, 4)),
self._antialiased, self.get_edgecolors().reshape((-1, 4)),
urls=self.get_urls())
else:
# This backend does not support storing urls in the QuadMesh.
renderer.draw_quad_mesh(
gc, transform.frozen(), self._meshWidth, self._meshHeight,
coordinates, offsets, transOffset,
# Backends expect flattened rgba arrays (n*m, 4) for fc
# and ec
self.get_facecolor().reshape((-1, 4)),
self._antialiased, self.get_edgecolors().reshape((-1, 4)))
gc.restore()
renderer.close_group(self.__class__.__name__)
self.stale = False
Expand Down
2 changes: 2 additions & 0 deletionslib/matplotlib/lines.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -761,6 +761,7 @@ def draw(self, renderer):
if len(tpath.vertices):
gc = renderer.new_gc()
self._set_gc_clip(gc)
gc.set_url(self.get_url())

lc_rgba = mcolors.to_rgba(self._color, self._alpha)
gc.set_foreground(lc_rgba, isRGBA=True)
Expand All@@ -787,6 +788,7 @@ def draw(self, renderer):
if self._marker and self._markersize > 0:
gc = renderer.new_gc()
self._set_gc_clip(gc)
gc.set_url(self.get_url())
gc.set_linewidth(self._markeredgewidth)
gc.set_antialiased(self._antialiased)

Expand Down
60 changes: 60 additions & 0 deletionslib/matplotlib/tests/test_backend_svg.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -214,3 +214,63 @@ def test_savefig_tight():
# Check that the draw-disabled renderer correctly disables open/close_group
# as well.
plt.savefig(BytesIO(), format="svgz", bbox_inches="tight")


def test_url():
# Test that object url appears in output svg.

fig, ax = plt.subplots()

# collections
s = ax.scatter([1, 2, 3], [4, 5, 6])
s.set_urls(['http://example.com/foo', 'http://example.com/bar', None])

# Line2D
p, = plt.plot([1, 3], [6, 5])
p.set_url('http://example.com/baz')

# QuadMesh
data = np.array([
[np.nan, 4, np.nan],
[2, 7, 5],
[np.nan, 8, np.nan]
])
links = np.array([
[np.nan, 'http://example.com/qux', np.nan],
['http://example.com/quux', 'http://example.com/quuz',
'http://example.com/corge'],
[np.nan, 'http://example.com/grault', np.nan]
])
ax.pcolormesh(data, urls=links)

b = BytesIO()
fig.savefig(b, format='svg')
b = b.getvalue()
for v in [b'foo', b'bar', b'baz', b'qux', b'quux', b'quuz', b'corge',
b'grault']:
assert b'http://example.com/' + v in b


def test_url_tick():
fig1, ax = plt.subplots()
ax.scatter([1, 2, 3], [4, 5, 6])
for i, tick in enumerate(ax.yaxis.get_major_ticks()):
tick.set_url(f'http://example.com/{i}')

fig2, ax = plt.subplots()
ax.scatter([1, 2, 3], [4, 5, 6])
for i, tick in enumerate(ax.yaxis.get_major_ticks()):
tick.label1.set_url(f'http://example.com/{i}')
tick.label2.set_url(f'http://example.com/{i}')

b1 = BytesIO()
fig1.savefig(b1, format='svg')
b1 = b1.getvalue()

b2 = BytesIO()
fig2.savefig(b2, format='svg')
b2 = b2.getvalue()

for i in range(len(ax.yaxis.get_major_ticks())):
assert f'http://example.com/{i}'.encode('ascii') in b1
assert b1 == b2

[8]ページ先頭

©2009-2025 Movatter.jp