|
|
|||||||||||||||||||||||||||||
|
pylab_examples_Examples 98_hyperlinks. |
H.Kamifuji . |
|
この例では、さまざまな種類の要素にハイパーリンクを設定する方法を示します。 これは現在、SVGバックエンドでのみ動作します。 この事例は、Windows10_1909 で Python 3.9.0 環境では、動作しません。( Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) がデグレートしたのか? )
# -*- noplot -*-
"""
This example demonstrates how to set a hyperlinks on various kinds of elements.
This currently only works with the SVG backend.
"""
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
f = plt.figure()
s = plt.scatter([1, 2, 3], [4, 5, 6])
s.set_urls(['http://www.bbc.co.uk/news', 'http://www.google.com', None])
f.canvas.print_figure('scatter.svg')
f = plt.figure()
delta = 0.025
x = y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = Z2 - Z1 # difference of Gaussians
im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray,
origin='lower', extent=[-3, 3, -3, 3])
im.set_url('http://www.google.com')
f.canvas.print_figure('image.svg')
|
|
Traceback (most recent call last): File "_:\hyperlinks.py", line 23, in <module> Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) ^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'matplotlib.mlab' has no attribute 'bivariate_normal' matplotlib 内部のエラーのようです。matplotlib の改修(先祖帰りバグの改修)を待つしかない。 Python 3.11.6 (matplotlib 3.7.1) では、下記のようなエラーがあり、image.svg が作成されない。 Traceback (most recent call last): File "M:\______\hyperlinks.py", line 23, inPython 3.12.0 (matplotlib 3.8.1) では、下記のようなエラーがあり、image.svg が作成されない。 Traceback (most recent call last): File "E:\______\hyperlinks.py", line 23, inPython 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) で、見直し中、新しいサンプル(misc-hyperlinks-sgskip-py) を見つけ、下記のコードで、正常に実行できました。
"""
==========
Hyperlinks
==========
This example demonstrates how to set a hyperlinks on various kinds of elements.
This currently only works with the SVG backend.
"""
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.cm as cm
# %%
fig = plt.figure()
s = plt.scatter([1, 2, 3], [4, 5, 6])
s.set_urls(['https://www.bbc.com/news', 'https://www.google.com/', None])
fig.savefig('scatter.svg')
# %%
fig = plt.figure()
delta = 0.025
x = y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2
im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray,
origin='lower', extent=(-3, 3, -3, 3))
im.set_url('https://www.google.com/')
fig.savefig('image.svg')
Python 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) 共に、正常実行です。 |
|
pylab_examples_Examples code: hyperlinks.py misc-hyperlinks-sgskip-py |
|