python - 是否可以在标题中创建带有 href 的绘图(matplotlib)?
问题描述
我想让这个链接互动,不幸的是它不显示任何 html 内容。有没有办法让这个标题成为一个href?
from matplotlib import pyplot as plt
import numpy as np
fig, axs1 = plt.subplots(1)
import numpy as np
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
axs1.plot(x)
axs1.set_title("<a href=vk.com>vk.com</a>")
plt.show()
解决方案
您可以使用以下方法将标题写为文本,而不是使用set_title
import numpy as np
from matplotlib import pyplot as plt
from IPython.display import set_matplotlib_formats
set_matplotlib_formats("svg")
fig, axs1 = plt.subplots(figsize=(6, 4))
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
axs1.plot(x, y)
text = axs1.annotate("vk.com", xy=(0.5,1), xytext=(0.5,0.96),
xycoords='figure fraction',
verticalalignment='top',
url='vk.com', fontsize=16)
plt.show()
推荐阅读
- python - TypeError:只能转换大小为 1 的数组
- jquery - 将jsp文件包含到其他jsp文件中时jquery包含两次
- vb.net - 打开文本文件并逐行读取
- python - 在Python中写入文件时合并行?
- java - 验证 vaadin 7 网格中的列值
- c - strcpy 与直接分配:溢出问题
- python - 如何在循环导入的情况下将 A 类的引用传递给 B 类,同时在 Pycharm 中保持类型提示和自动完成功能
- google-apps-script - 如果单元格文本有删除线,脚本将单元格颜色设置为无?
- sql-server - 如何在循环匹配条件下更新 Sql Server 表的记录?
- c++ - C++:reinterpret_cast 在这些场景中是最佳选择吗?