pyecharts / pyecharts-snapshot Goto Github PK
View Code? Open in Web Editor NEWrenders the output of pyecharts as png, jpeg, gif, svg, eps, pdf and raw base64
renders the output of pyecharts as png, jpeg, gif, svg, eps, pdf and raw base64
i want to use it in python to turn encharts.html into png, how can i do this?
如题,不然会出现截图缺失问题,就不提交 PR 了,你自己修改就行了 @chfw
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot
def bar_chart() -> Bar:
c = (
Bar()
.add_xaxis(["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"])
.add_yaxis("商家A", [114, 55, 27, 101, 125, 27, 105])
.add_yaxis("商家B", [57, 134, 137, 129, 145, 60, 49])
.reversal_axis()
.set_series_opts(label_opts=opts.LabelOpts(position="right"))
.set_global_opts(title_opts=opts.TitleOpts(title="Bar-测试渲染图片"))
)
return c
make_snapshot(snapshot, bar_chart().render(), "bar0.png")
OSError Traceback (most recent call last)
in ()
17 return c
18
---> 19 make_snapshot(snapshot, bar_chart().render(), "bar0.png")
~\Program File\Anaconda3\lib\site-packages\pyecharts\render\snapshot.py in make_snapshot(engine, file_name, output_name, delay, pixel_ratio, is_remove_html, **kwargs)
37 content_array = content.split(",")
38 if len(content_array) != 2:
---> 39 raise OSError(content_array)
40
41 image_data = decode_base64(content_array[1])
OSError: ["ReferenceError: Can't find variable: echarts\n\n undefined:1\nnull\n"]
Python 3.6
pyecharts == 1.5.1
pyecharts-javascripthon==0.0.6
pyecharts-jupyter-installer==0.0.3
pyecharts-snapshot==0.1.7
'phantomjs' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
Traceback (most recent call last):
File "H:/project/python/web/xmshop/test/2.py", line 13, in
make_a_snapshot('render2.html', 'snapshot.png')
File "D:\Program Files (x86)\python\pythonenv\lib\site-packages\pyecharts_snapshot\main.py", line 60, in make_a_snapshot
base64_imagedata = content.split(',')[1]
IndexError: list index out of range
I used snapshot to generate a chart, png format, the file size is about 12M+. Is there any approach to reduce the file size? Thank you!
pyecharts-snapshot 0.2.0 has a bug:
create_default_environment('html') is ok and create_default_environment('png') is error.
pyecharts-snapshot 0.1.10 everything is ok.
你好,
输入数据为data_scatter:
[('TRBV10-3', 'TRBD1', 'TRBJ1-1', 1, 1), ('TRBV10-3', 'TRBD1', 'TRBJ1-5', 1, 9), ('TRBV10-3', 'TRBD1', 'TRBJ2-7', 1, 2), ('TRBV11-2', 'TRBD1', 'TRBJ1-3', 1, 5), ('TRBV11-2', 'TRBD1', 'TRBJ1-4', 1, 6), ('TRBV12-3', 'TRBD1', 'TRBJ2-1', 1, 7), ('TRBV12-4', 'TRBD2', 'TRBJ2-1', 1, 3), ('TRBV13', 'TRBD1', 'TRBJ2-3', 3, 45), ('TRBV15', 'TRBD1', 'TRBJ1-4', 2, 4), ('TRBV18', 'TRBD1', 'TRBJ1-5', 1, 12), ('TRBV18', 'TRBD1', 'TRBJ2-4', 1, 6), ('TRBV2', 'TRBD1', 'TRBJ1-4', 1, 3), ('TRBV2', 'TRBD1', 'TRBJ2-5', 1, 5), ('TRBV20-1', 'TRBD1', 'TRBJ1-4', 1, 10), ('TRBV20-1', 'TRBD1', 'TRBJ2-2', 1, 5), ('TRBV20-1', 'TRBD1', 'TRBJ2-3', 1, 11), ('TRBV25-1', 'TRBD1', 'TRBJ1-2', 1, 3), ('TRBV29-1', 'TRBD1', 'TRBJ2-5', 3, 21), ('TRBV5-1', 'TRBD1', 'TRBJ1-2', 1, 10), ('TRBV5-1', 'TRBD1', 'TRBJ2-1', 1, 4), ('TRBV5-1', 'TRBD1', 'TRBJ2-4', 1, 7), ('TRBV5-4', 'TRBD1', 'TRBJ1-4', 1, 3), ('TRBV5-4', 'TRBD1', 'TRBJ2-7', 1, 12), ('TRBV5-5', 'TRBD1', 'TRBJ2-1', 1, 7), ('TRBV5-6', 'TRBD2', 'TRBJ2-1', 1, 2), ('TRBV6-1', 'TRBD2', 'TRBJ2-7', 1, 5), ('TRBV6-5', 'TRBD1', 'TRBJ1-1', 1, 1), ('TRBV6-5', 'TRBD1', 'TRBJ1-3', 1, 9), ('TRBV6-5', 'TRBD1', 'TRBJ2-2', 1, 16), ('TRBV6-5', 'TRBD1', 'TRBJ2-7', 1, 7), ('TRBV6-6', 'TRBD1','TRBJ1-5', 1, 3), ('TRBV6-6', 'TRBD1', 'TRBJ1-6', 1, 8), ('TRBV6-6', 'TRBD2', 'TRBJ2-7', 1, 5), ('TRBV6-9', 'TRBD1', 'TRBJ1-4', 1, 5), ('TRBV7-2', 'TRBD1', 'TRBJ1-2', 1, 7), ('TRBV7-2', 'TRBD1', 'TRBJ2-5', 1, 5), ('TRBV7-8', 'TRBD1', 'TRBJ1-2', 1, 2), ('TRBV7-8', 'TRBD1', 'TRBJ2-1', 1, 6), ('TRBV7-8', 'TRBD1', 'TRBJ2-6', 1, 13), ('TRBV9', 'TRBD2', 'TRBJ2-1', 2, 8)]
画图代码为:
file_path="{}/".format(os.path.dirname(os.path.abspath("./echarts.min.js")))
def scatter3d() -> Scatter3D:
c = (
Scatter3D(init_opts = opts.InitOpts(width='900px',height='700px', js_host=file_path))
.add("",
data_scatter,
xaxis3d_opts=opts.Axis3DOpts(
name="v-gene",
type_="category",
),
yaxis3d_opts=opts.Axis3DOpts(
name="d-gene",
type_="category",
),
zaxis3d_opts=opts.Axis3DOpts(
name="j-gene",
type_="category",
),
grid3d_opts = opts.Grid3DOpts(width=100, depth=90, rotate_speed = 90, is_rotate=False)
)
.set_global_opts(title_opts=opts.TitleOpts(title="Scatter3D of VDJ-pairs"),
visualmap_opts=[
opts.VisualMapOpts(type_="color", dimension=4, pos_top="40", max_= max(data_filter['umis'].tolist())),
opts.VisualMapOpts(type_="size", dimension=3, pos_bottom="40", max_= max(data_filter['barcodes'].tolist()), range_size=[1, max(data_filter['barcodes'].tolist())*5],
),
]
)
)
return c
scatter3d_png = os.path.join(od_path, "Scatter3D_vdj_pairs.png")
make_snapshot(snapshot, scatter3d().render(), scatter3d_png)
生成的PNG是空的。
我把echarts.min.js下载到linux,Sankey图按照这个模式是可以生成PNG 和PDF的,但是Scatter3D不知道为什么不行
盼复
Windows 7 with Python 2.7, with the latest pyecharts and pyecharts-snapshot from github.
os.path
module won't work. Change it to back slash works.radar.render("pics\\index.html")
make_a_snapshot("pics\\index.html", "pics\\echarts_radar3.png")
Result:
\lib\site-packages\pyecharts_snapshot\main.py", line 64, in make_a_snapshot
base64_imagedata = content.split(',')[1]
IndexError: list index out of range
在完整的一个ipynb中,需要多次调用make_a_snapshot生成png图片,这导致在程序运行一部分时,电脑内存爆掉,所以希望优化下性能。之前直接利用bar或者line直接生成,未出现此问题,但是导出为PDF不能显示。
我的一个ipynb中,多次利用了make_a_snapshot,前面的十几个图片可以截图成功,到13张图片的时候,就开始报错No phantomjs found in your PATH. Please install it!
An exception has occurred, use %tb to see the full traceback.
SystemExit: 1
我的phantomjs已经安装好了,前面的截图也已经成功了,不知道为什么中途就出问题了
在分布式场景下,只能直接返回图片,能否添加一个函数,直接返回图片base64的编码? 最好不要复用render 方法
如题,不过make_a_snapshot的方法可以使用。
zxjd@zxjd-OptiPlex-7040:~$ snapshot render.html
Traceback (most recent call last):
File "/usr/local/bin/snapshot", line 11, in
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/pyecharts_snapshot/main.py", line 35, in main
make_a_snapshot(file_name, output, delay=delay)
File "/usr/local/lib/python2.7/dist-packages/pyecharts_snapshot/main.py", line 54, in make_a_snapshot
proc_params, stdout=subprocess.PIPE, shell=shell_flag)
File "/usr/lib/python2.7/subprocess.py", line 711, in init
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
hello,every friends, I have a problem now, who can help me? thanks very much~
when I create a html file the legend is intact, but when I use the snapshot to create a png/gif, the title、the lables and the legend are all disappear.
ps: the operating system is Red Hat 4.4.7-16; node version is v10.4.0; phantomjs version is 2.1.1.
When I run a html file using "snapshot render.html svg", what are the some errors ? How to resovle it?
Generating file ...
Traceback (most recent call last):
File "/usr/local/bin/snapshot", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/pyecharts_snapshot/main.py", line 86, in main
asyncio.get_event_loop().run_until_complete(_main())
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 583, in run_until_complete
return future.result()
File "/usr/local/lib/python3.7/site-packages/pyecharts_snapshot/main.py", line 109, in _main
file_name, output, delay=delay, pixel_ratio=pixel_ratio
File "/usr/local/lib/python3.7/site-packages/pyecharts_snapshot/main.py", line 130, in make_a_snapshot
file_name, file_type, pixel_ratio, delay
File "/usr/local/lib/python3.7/site-packages/pyecharts_snapshot/main.py", line 169, in async_make_snapshot
return await get_echarts(to_file_uri(html_path), snapshot_js)
File "/usr/local/lib/python3.7/site-packages/pyecharts_snapshot/main.py", line 173, in get_echarts
browser = await launch()
File "/usr/local/lib/python3.7/site-packages/pyppeteer/launcher.py", line 305, in launch
return await Launcher(options, **kwargs).launch()
File "/usr/local/lib/python3.7/site-packages/pyppeteer/launcher.py", line 166, in launch
self.browserWSEndpoint = get_ws_endpoint(self.url)
File "/usr/local/lib/python3.7/site-packages/pyppeteer/launcher.py", line 225, in get_ws_endpoint
raise BrowserError('Browser closed unexpectedly:\n')
pyppeteer.errors.BrowserError: Browser closed unexpectedly:
我生成了一个动态图表,在以html为格式时可交互也可以动态,但是输出成gif或者svg就不能动态和交互,而且README中的svg示例已经挂了...
在issue 23看到跟我同样报错的信息,看到作者提交了commit和终止了问题后
我把作者的回复操作试了一遍
但是发现还是没有成功解决我的 问题
这是我的错误信息
phantomjs version: 2.1.1
Generating file ...
Traceback (most recent call last):
File "E:\学习作业\毕业设计\爬虫\数据分析\output_jinjiang.py", line 10, in
bar.render(path='snapshot.png', pixel_ratio=3)
File "D:\Program Files\python\lib\site-packages\pyecharts\base.py", line 146, in render
**kwargs
File "D:\Program Files\python\lib\site-packages\pyecharts_snapshot\environment.py", line 35, in render_chart_to_file
make_a_snapshot(tmp_file_path, path, delay=delay, verbose=verbose)
File "D:\Program Files\python\lib\site-packages\pyecharts_snapshot\main.py", line 99, in make_a_snapshot
raise OSError(content_array)
OSError: ["ReferenceError: Can't find variable: echarts\n\n undefined:1\nnull\n"]
[Finished in 6.0s]
使用的是有我自己的代码和作者的案例代码,还有尝试了作者说的引擎方式,但都是同样的错误
无论是这个案例
还是这个案例
`from pyecharts import Bar, Line
from pyecharts.engine import create_default_environment
bar = Bar("我的第一个图表", "这里是副标题")
bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90])
line = Line("我的第一个图表", "这里是副标题")
line.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90])
env = create_default_environment("html")
env.render_chart_to_file(bar, path='bar.html')
env.render_chart_to_file(line, path='line.html')`
都是报了同一个错误
我的尝试结果是,如果不用引擎的方式,我可以生成html文件,但是png文件始终无法生成
我的python版本是3.6
使用的是sublime text编辑器
版本信息有
pyecharts==0.5.11
pyecharts-javascripthon==0.0.6
pyecharts-jupyter-installer==0.0.3
pyecharts-snapshot==0.1.7
PyInstaller==3.3.1
以上是我的问题详细内容,跪求作者翻牌,谢谢大佬
when I run snapshot test.html gif in command line , It gives me a static picture, not a gif, How can I got a dynamic gif file?
描述:
pyecharts将图片保存成jpeg的时候,背景色变成黑色。
保存成png则没有问题,但是图片没有压缩,9M太大了。
版本:
pyecharts 0.5.11
pyecharts-snapshot 0.1.10
代码:
bar_image = pyecharts.Bar(”title‘’, width=1200, height=700)
bar_image.add(‘long’, long_interval_array,
long_frequency_array)
bar_image.add('short', short_interval_array,
short_frequency_array)
bar_image.render(path='test.jpeg')
I use python2.7.10 run this https://github.com/pyecharts/pyecharts-snapshot/blob/master/examples/pdf.py file , can't get right pdf file, change output file name to *.html ,then can see the right graph. no errors. i installed pyecharts-snapshot, pyecharts and phantomjs.
how can I get right file? thank your.
Generating file ...
Traceback (most recent call last):
File "d:\anaconda3\envs\venv37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\anaconda3\envs\venv37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\Anaconda3\envs\venv37\Scripts\snapshot.exe\__main__.py", line 7, in <module>
File "d:\anaconda3\envs\venv37\lib\site-packages\pyecharts_snapshot\main.py", line 86, in main
asyncio.get_event_loop().run_until_complete(_main())
File "d:\anaconda3\envs\venv37\lib\asyncio\base_events.py", line 583, in run_until_complete
return future.result()
File "d:\anaconda3\envs\venv37\lib\site-packages\pyecharts_snapshot\main.py", line 109, in _main
file_name, output, delay=delay, pixel_ratio=pixel_ratio
File "d:\anaconda3\envs\venv37\lib\site-packages\pyecharts_snapshot\main.py", line 130, in make_a_snapshot
file_name, file_type, pixel_ratio, delay
File "d:\anaconda3\envs\venv37\lib\site-packages\pyecharts_snapshot\main.py", line 169, in async_make_snapshot
return await get_echarts(to_file_uri(html_path), snapshot_js)
File "d:\anaconda3\envs\venv37\lib\site-packages\pyecharts_snapshot\main.py", line 175, in get_echarts
await page.goto(url)
File "d:\anaconda3\envs\venv37\lib\site-packages\pyppeteer\page.py", line 862, in goto
raise error
pyppeteer.errors.TimeoutError: Navigation Timeout Exceeded: 30000 ms exceeded.
mac os phantomjs already setup. python3.7
from pyecharts import options as opts
from pyecharts.charts import Gauge
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot
import os
def bar_chart():
c = (
Gauge(init_opts=opts.InitOpts(bg_color="white"))
.add(
"",
[("AA", 40.4)], title_label_opts=opts.LabelOpts(
font_size=22, font_weight='700', color="#00BEE6", font_family="Microsoft YaHei"),
split_number=10,
axisline_opts=opts.AxisLineOpts(
linestyle_opts=opts.LineStyleOpts(
color=[[0.2, "#67e0e3"], [0.8, "#37a2da"], [1, "#fd666d"]], width=30
)
),
detail_label_opts=opts.LabelOpts(formatter="{value}%"),
)
.set_global_opts(
title_opts=opts.TitleOpts(),
legend_opts=opts.LegendOpts(is_show=False),
)
)
make_snapshot(snapshot, c.render(), "TEST.png",is_remove_html=False)
if name == 'main':
bar_chart()
在不连网的情况下,在win10系统下上述代码会报错
_### _File "C:\software\anaconda\lib\site-packages\pyecharts\render\snapshot.py", line 45, in make_snapshot
raise OSError(content_array)
OSError: ["ReferenceError: Can't find variable: echarts\n\n file:///H:/Python/python/render.html:12 in global code\nReferenceError: Can't find variable: echarts\n\n undefined:1\nnull\n"]__
怎么正确在Gauge(init_opts=opts.InitOpts(bg_color="white"))中opts_InitOpts添加js_host使得代码能运行?
File "grid.py", line 4, in
from pyecharts import Bar, Grid, Line, Scatter, EffectScatter
ImportError: cannot import name 'Bar'
C:\python3\python "1.py" (在目录 C:\Users\85422\Desktop 中)
phantomjs version: 2.1.1
Generating file ...
Traceback (most recent call last):
File "1.py", line 11, in
bar.render(path='snapshot.png')
File "C:\python3\lib\site-packages\pyecharts\base.py", line 132, in render
**kwargs
File "C:\python3\lib\site-packages\pyecharts_snapshot\environment.py", line 35, in render_chart_to_file
make_a_snapshot(tmp_file_path, path, delay=delay, verbose=verbose)
File "C:\python3\lib\site-packages\pyecharts_snapshot\main.py", line 100, in make_a_snapshot
raise OSError(content_array)
OSError: ["ReferenceError: Can't find variable: echarts\n\n undefined:1\nnull\n"]
编译失败。
Vector graphics are essential for organizing the figures in manuscript. Can sankey plot be converted to vectorgraph like pdf or SVG file? Thanks a lot!
您好,我希望利用pyecharts生成svg格式,但转换后的svg文件无法显示图片,请问这个是因为没有加入渲染,还是什么问题嘛
from pyecharts import options as opts
from pyecharts import render
from pyecharts.charts import Bar
from pyecharts.globals import RenderType
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot
//from snapshot_selenium import snapshot
def bar_chart() -> Bar:
c = (
Bar()
.add_xaxis(["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"])
.add_yaxis("商家A", [114, 55, 27, 101, 125, 27, 105])
.add_yaxis("商家B", [57, 134, 137, 129, 145, 60, 49])
.reversal_axis()
.set_series_opts(label_opts=opts.LabelOpts(position="right"))
.set_global_opts(title_opts=opts.TitleOpts(title="Bar-测试渲染图片"))
)
return c
make_snapshot(snapshot, bar_chart().render(), "bar0.svg")
bar_chart().render('bar0.html')
make_snapshot(snapshot, 'bar0.html', "bar0.svg")
通过命令行 snapshot bar0.html svg 方式获取,同样打开是如下格式
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<canvas data-zr-dom-id="zr_0" width="900" height="500" style="position: absolute; left: 0px; top: 0px; width: 900px; height: 500px; user-select: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); padding: 0px; margin: 0px; border-width: 0px;"/>
In my python, it seems that the delay wouldn't work. No matter what kinds of number I type in, it just wouldn't work. And the pic it generates is damaged. I can't open it. But the html file is ok. Weird.
运行Example programs报错“IndexError: list index out of range”
`IndexError Traceback (most recent call last)
in ()
11 bar.add("商家B", attr, v2, is_stack=True)
12 bar.render()
---> 13 make_a_snapshot('render.html', 'snapshot.png')
D:\ProgramData\lib\site-packages\pyecharts_snapshot\main.py in make_a_snapshot(file_name, output_name)
53 else:
54 content = io.TextIOWrapper(proc.stdout, encoding="utf-8").read()
---> 55 base64_imagedata = content.split(',')[1]
56 imagedata = decode_base64(base64_imagedata.encode('utf-8'))
57 if file_type == 'pdf':
IndexError: list index out of range`
我已经照着安装了,怎么还有bug?
1.安装了 node.js 环境
2.安装 phantomjs
npm install -g phantomjs-prebuilt
3.安装 pyecharts-snapshot
pip install pyecharts-snapshot
4.引入 pyecharts-snapshot
from pyecharts_snapshot.main import make_a_snapshot
make_a_snapshot('render.html', 'snapshot.png')’
Hi,
I'm trying to run pyecharts-snapshot inside my WSL2-ubuntu env and for this reason there is no browser. Is there any workaround?
@chfw Have you updated this on pypi yet?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.