pygal图表在Jupyter/IPython笔记本中不显示工具提示

pygal图表在Jupyter/IPython笔记本中不显示工具提示,python,svg,ipython,jupyter-notebook,pygal,Python,Svg,Ipython,Jupyter Notebook,Pygal,经过大量研究,我终于获得了工具提示,因此: 在生成的.svg中,工具提示现在可以很好地工作,但只有在浏览器中打开文件时才可以 当图表直接以Jupyter显示时(使用IPython.core.display.SVG(filename=“bar\u chart.SVG”)或仅使用bar\u chart),工具提示和样式将不存在 这是已知的限制吗?或者它可以实现吗?在谷歌搜索中找到,这让我想到了这个问题。如果您阅读pygal文档或查看它生成的SVG示例,您将看到它包含pygal.js,这在您的笔记本中

经过大量研究,我终于获得了工具提示,因此:

在生成的.svg中,工具提示现在可以很好地工作,但只有在浏览器中打开文件时才可以

当图表直接以Jupyter显示时(使用
IPython.core.display.SVG(filename=“bar\u chart.SVG”)
或仅使用
bar\u chart
),工具提示和样式将不存在


这是已知的限制吗?或者它可以实现吗?

在谷歌搜索中找到,这让我想到了这个问题。如果您阅读pygal文档或查看它生成的SVG示例,您将看到它包含pygal.js,这在您的笔记本中是不存在的。

我的解决方法是使用必要的javascript和图表SVG设置HTML,如下所示:

import pygal
from IPython.display import display, HTML

base_html = """
<!DOCTYPE html>
<html>
  <head>
  <script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/svg.jquery.js"></script>
  <script type="text/javascript" src="https://kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js""></script>
  </head>
  <body>
    <figure>
      {rendered_chart}
    </figure>
  </body>
</html>
"""

def galplot(chart):
    rendered_chart = chart.render(is_unicode=True)
    plot_html = base_html.format(rendered_chart=rendered_chart)
    display(HTML(plot_html))

bar_chart = pygal.StackedBar()
bar_chart.add('Bars', [1,2,3,4,5])

galplot(bar_chart)
导入pygal
从IPython.display导入显示,HTML
base_html=“”

你解决你的问题了吗?我这里也有同样的问题(即:pygal+jupyter没有工具提示)
import pygal
from IPython.display import display, HTML

base_html = """
<!DOCTYPE html>
<html>
  <head>
  <script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/svg.jquery.js"></script>
  <script type="text/javascript" src="https://kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js""></script>
  </head>
  <body>
    <figure>
      {rendered_chart}
    </figure>
  </body>
</html>
"""

def galplot(chart):
    rendered_chart = chart.render(is_unicode=True)
    plot_html = base_html.format(rendered_chart=rendered_chart)
    display(HTML(plot_html))

bar_chart = pygal.StackedBar()
bar_chart.add('Bars', [1,2,3,4,5])

galplot(bar_chart)