Python 教程:从plotly plot自动导出矢量图形(PDF)
最近我想知道是否可以从plotly自动导出绘图。不幸的是,plotly的文档只是一个笑话,模块希望您为这样的基本功能付费。在免费版本中,只能以非矢量格式(png)自动导出。在这里,我想介绍一个依赖于phantomjs的解决方案。步骤1:生成html文件 注意:这在html文件中包含了plotly.js的大部分内容。仅此一项就占用大约2MB。如果需要,将Python 教程:从plotly plot自动导出矢量图形(PDF),python,plot,phantomjs,plotly,vector-graphics,Python,Plot,Phantomjs,Plotly,Vector Graphics,最近我想知道是否可以从plotly自动导出绘图。不幸的是,plotly的文档只是一个笑话,模块希望您为这样的基本功能付费。在免费版本中,只能以非矢量格式(png)自动导出。在这里,我想介绍一个依赖于phantomjs的解决方案。步骤1:生成html文件 注意:这在html文件中包含了plotly.js的大部分内容。仅此一项就占用大约2MB。如果需要,将include_plotlyjs更改为False并在html文件中引用plotly.js: <script src="path/to/plo
include_plotlyjs
更改为False
并在html文件中引用plotly.js:
<script src="path/to/plotly.js"></script>
这需要4个参数:html文件的路径、输出文件路径、输出文件的宽度和高度
步骤3:从python调用PhantomJS脚本
这将调用phantomjs,并将从上面到javascript的路径、到html文件的路径、输出文件路径以及宽度和高度作为参数传递
我希望这对某人有用非常感谢!不过,我无法让它处理3D图像。运行phantomjs会产生:
TypeError:undefined不是对象(评估't.glplot.canvas')
,生成的pdf只显示标题和图例,并告诉我我的浏览器不支持Webgl。有什么想法吗?
<script src="path/to/plotly.js"></script>
var page = require('webpage').create();
var system = require('system');
var args = system.args;
page.viewportSize = { width: args[3], height: args[4] };
page.clipRect = { top: 0, left: 0, width: args[3], height: args[4] };
page.open(args[1], function() {
page.render(args[2]);
phantom.exit();
});
import subprocess
xSize = 1280
ySize = 1024
subprocess.check_output(
['phantomjs', 'phantom_html_to_PDF.js', 'temp.html', out_path, str(x_Size), str(y_Size)])
#remove temporary html file
subprocess.check_output(['rm', 'temp.html])