Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎样在Jupyter Notebook中显示图表? #5

Closed
uuleejie opened this issue Jul 23, 2017 · 26 comments
Closed

怎样在Jupyter Notebook中显示图表? #5

uuleejie opened this issue Jul 23, 2017 · 26 comments

Comments

@uuleejie
Copy link

你好,将有关代码粘贴到notebook中后运行,没有报错,也没有显示图表。请问应该怎样做才能显示图表?

@uuleejie
Copy link
Author

看看文档后知道了,不用回复,谢谢!

@Chandlerwu007
Copy link

文档中没有看见呀

@chenjiandongx
Copy link
Member

@Chandlerwu007 用浏览器打开生成 .html 文件 默认为 render.html

@Chandlerwu007
Copy link

恩。。打开了。试了下,好像不能指定存放路径。

@Chandlerwu007
Copy link

对浏览器有什么要求么?在家里电脑能正常显示,但在单位上的显示为空白。

@Lving
Copy link

Lving commented Jul 24, 2017

其实 jupyter 是支持js的

@ygw365
Copy link

ygw365 commented Jul 24, 2017

in /pyecharts-master/pyecharts/base.py

    def render2(self):
        import datetime
        divid = datetime.datetime.now()
        my_option = json.dumps(self._option, indent=4)
        s = '''
        <div id="{{ chartid }}" style="width:800px; height:600px;"></div>
<script>
    require.config({
         paths:{
            echarts: '//cdn.bootcss.com/echarts/3.2.3/echarts.min',
         }
    });
    require(['echarts'],function(ec){
    var myChart = ec.init(document.getElementById('{{ chartid }}'));
               var option =  {{ opt }};
                myChart.setOption(option);
    });
</script>
'''
        tmp = Template(s)
        return tmp.render(opt=my_option.decode('utf8'),chartid=divid)

in notebook:

from pyecharts import Bar

bar = Bar("标记线和标记点示例")
bar.add("商家A", attr, v1, mark_point=["average"])
bar.add("商家B", attr, v2, mark_line=["min", "max"])
HTML(bar.render2())

snip20170724_3

@chenjiandongx
Copy link
Member

chenjiandongx commented Jul 24, 2017

@ygw365
谢谢你的贡献 欢迎各位参与到项目开发中哈

@ygw365
Copy link

ygw365 commented Jul 24, 2017

@chenjiandongx chen,已经提了PR,你看下

@foodish
Copy link

foodish commented Jul 27, 2017

@ygw365 添加了您的代码,不过有错误。没有Template函数。。。

@chenjiandongx
Copy link
Member

chenjiandongx commented Jul 27, 2017

Guys, now you can show your charts in jupyter notebook.It will be a cool features.enjoy it!
specific introduction -> https://github.com/chenjiandongx/pyecharts/blob/master/README.md#开始使用

@foodish
Copy link

foodish commented Jul 27, 2017

升级后可以完美显示了,感谢 @chenjiandongx

@ygw365
Copy link

ygw365 commented Jul 28, 2017

@foodish , pip install jinja2

@foodish
Copy link

foodish commented Jul 28, 2017

@ygw365 最新版已经好了。感谢!

@xbanke
Copy link
Contributor

xbanke commented Jul 28, 2017

@chenjiandongx 已经更新了,在notebook中可以正常显示,但如果 下载为html的话,可能因为改变了跟路径,无法加载相应js文件,进而无法显示echarts图。

@chenjiandongx
Copy link
Member

@xbanke
使用 render() 方法仍然会在本地保存一个 .html 文件,render_notebook() 只是专门为 notebook 提供的新方法而已

@xbanke
Copy link
Contributor

xbanke commented Jul 28, 2017

@chenjiandongx 我明白你的意思,用render只能保存那张图。notebook其中一个很重要的场景就是可以导出各类格式的文件进行分享,只是在生成html时,echarts的图有问题,当然这可能要改notebook的配置,而不是pyecharts

@chenjiandongx
Copy link
Member

@xbanke
就是因为正常的 html echart 文件在 notebook 中不能正常显示,才花了那么多时间来测试能确保 notebook 所有图形正常显示的 Js 代码

@yi1260
Copy link

yi1260 commented Jul 28, 2017

jupyter的远程模式还是显示不了@chenjiandongx 已经是最新版本了, 是只能在本地模式下才行吗

@chensonglovelife
Copy link

chensonglovelife commented Jul 28, 2017

1.8 version still has this bug.python2.7 + v1.8 + chrome of Mac

@chenjiandongx
Copy link
Member

chenjiandongx commented Jul 28, 2017

@chensonglovelife I do not test on Mac

@chenjiandongx
Copy link
Member

@yi1260
我没这么测试过 现在还是不可以吗

@lf-shaw
Copy link

lf-shaw commented Jul 31, 2017

@yi1260 远程模式要加载相应的资源,bokeh 里有类似的解决方法

from bokeh.io import output_notebook
output_notebook()

可以参考其实现 notebook

@chfw
Copy link
Member

chfw commented Jul 31, 2017

@chenjiandongx , could you please share you jupyter notebook on github? I can try my best to include a unit test for those notebooks. Tavis-ci will then verify your notebook per each commit, functionally. With that said, visual check is still required. However, with 700+ stars, there are plenty of eyes for that check :).

@xbanke
就是因为正常的 html echart 文件在 notebook 中不能正常显示,才花了那么多时间来测试能确保 notebook 所有图形正常显示的 Js 代码

@wqw547243068
Copy link

wqw547243068 commented Jun 8, 2018

image
为什么会出现这种情况?linux服务器上的jupyter环境无法正常显示图表
安装列表:

pyecharts 0.5.5
pyecharts-javascripthon 0.0.6
pyecharts-jupyter-installer 0.0.3

from pyecharts import WordCloud
name = [
    'Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications',
    'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp',
    'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham',
    'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']
value = [
    10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112,
    965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]
wordcloud = WordCloud(width=1300, height=620)
wordcloud.add("", name, value, word_size_range=[20, 100])
wordcloud.render('wordcloud.html')
wordcloud

@chfw
Copy link
Member

chfw commented Jun 8, 2018

if your jupyter host is not localhost:8888, you will have a problem. And we do not support other jupyter domain as of now. One solution is to do the following before your code:

from pyecharts import online

online()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests