Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Jupyter笔记本中呈现交互式Pygal图表_Python_Charts_Jupyter Notebook_Render_Pygal - Fatal编程技术网

Python 在Jupyter笔记本中呈现交互式Pygal图表

Python 在Jupyter笔记本中呈现交互式Pygal图表,python,charts,jupyter-notebook,render,pygal,Python,Charts,Jupyter Notebook,Render,Pygal,我试图在Jupyter笔记本中呈现交互式Pygal图表,但没有成功。我不是在寻找图像静态版本的解决方案,它工作得很好,而是一个具有交互式工具提示的解决方案 这个问题以前已经解决过: 但不幸的是,没有人遇到我的问题:实现这些链接中提供的解决方案,Jupyter,似乎无法正确地呈现图表,而是一个非常长的字符串。 不会产生错误 我遗漏了什么?我不会假装理解为什么,但切换到Unicode字符串可以解决问题。这可能就是为什么很少有人遇到这个问题:在Python3中,默认情况下所有字符串都是Unic

我试图在Jupyter笔记本中呈现交互式Pygal图表,但没有成功。我不是在寻找图像静态版本的解决方案,它工作得很好,而是一个具有交互式工具提示的解决方案

这个问题以前已经解决过:

但不幸的是,没有人遇到我的问题:实现这些链接中提供的解决方案,Jupyter,似乎无法正确地呈现图表,而是一个非常长的字符串。 不会产生错误


我遗漏了什么?

我不会假装理解为什么,但切换到Unicode字符串可以解决问题。这可能就是为什么很少有人遇到这个问题:在Python3中,默认情况下所有字符串都是Unicode

您需要将模板声明为Unicode文本,方法是在字符串前面加上
u
。然后告诉pygal在呈现图表时返回Unicode,方法是将
is_Unicode=True
作为参数传递给
render
函数

例如:

from IPython.display import HTML
import pygal

html_pygal = u"""
    <!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="http://kozea.github.com/pygal.js/javascripts/pygal-tooltips.js"></script>
        </head>
        <body><figure>{pygal_render}</figure></body>
    </html>
"""

line_chart = pygal.Line()
line_chart.title = "Browser usage evolution (in %)"
line_chart.x_labels = map(str, range(2002, 2013))
line_chart.add("Firefox", [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1])
line_chart.add("Chrome", [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3])
line_chart.add("IE", [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
line_chart.add("Others", [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5])
HTML(html_pygal.format(pygal_render=line_chart.render(is_unicode=True)))
从IPython.display导入HTML
进口皮加尔
html_pygal=u”“”
{pygal_render}
"""
line_chart=pygal.line()
line_chart.title=“浏览器使用演变(单位%)”
line_chart.x_labels=map(str,range(2002,2013))
添加(“Firefox”、[None、None、0、16.6、25、31、36.4、45.5、46.3、42.8、37.1])
折线图。添加(“Chrome”,[None,None,None,None,None,0,3.9,10.8,23.8,35.3])
折线图。添加(“IE”、[85.8、84.6、84.7、74.5、66、58.6、54.7、44.8、36.2、26.6、20.1])
折线图。添加(“其他”、[14.2、15.4、15.3、8.9、9、10.4、8.9、5.8、6.7、6.8、7.5])
HTML(HTML_pygal.format(pygal_render=line_chart.render(is_unicode=True)))

好吧,那是一个扫帚匠。您使用的pygal和jupyter版本是什么?您使用的是jupyter笔记本电脑还是lab?我使用的是Python 2.7.15(来自jupyter中的sys.version)和jupyter 4.4.0(笔记本电脑)。你是对的,这是一个真正的头巾,我一直在尝试不同的设置,但没有运气到目前为止。。。