如何在IPython Notebook中将Matplotlib图作为HTML抓取? [英] How to grab matplotlib plot as html in ipython notebook?
问题描述
我有一个IPython Notebook,它正在使用Pandas对基于规则的交易系统进行回测.
I have an IPython Notebook that is using Pandas to back-test a rule-based trading system.
我有一个函数,可以接受各种标量并将其作为参数,并输出统计数据包(如一些表格和一些图表).
I have a function that accepts various scalars and functions as parameters and outputs a stats pack as some tables and a couple of plots.
对于自动化,我希望能够将其很好地格式化为一个页面",然后在改变输入的同时循环调用该函数,并使其输出多个页面进行比较,所有这些均来自单个笔记本单元.
For automation, I want to be able to format this nicely into a "page" and then call the function in a loop while varying the inputs and have it output a number of pages for comparison, all from a single notebook cell.
我采用的方法是创建IpyTables,然后调用_repr_html_(),并逐步构建HTML输出,以便最终从运行循环的函数中将其返回.
The approach I am taking is to create IpyTables and then call _repr_html_(), building up the HTML output along the way so that I can eventually return it from the function that runs the loop.
我如何以这种方式捕获绘图的输出-matplotlib子绘图对象似乎未实现_repr_html _()?
How can I capture the output of the plots this way - matplotlib subplot objects don't seem to implement _repr_html_()?
可以随意提出另一种您认为同样可以解决问题的方法.
Feel free to suggest another approach entirely that you think might equally solve the problem.
TIA
推荐答案
好吧,如果您走那条路,这个答案stackoverflow.com/a/5314808/243434有关如何捕获> matplotlib数字作为内联PNG可能会有所帮助– @crewbum
Ok, if you go that route, this answer stackoverflow.com/a/5314808/243434 on how to capture >matplotlib figures as inline PNGs may help – @crewbum
为防止重复绘制,请尝试在禁用pylab的情况下运行(仔细检查config> files和命令行). – @crewbum
To prevent duplication of plots, try running with pylab disabled (double-check your config >files and the command line). – @crewbum
->这最后一次需要重新启动笔记本:ipython notebook --pylab(不带内联功能)
--> this last requires a restart of the notebook: ipython notebook --pylab (NB no inline)
这篇关于如何在IPython Notebook中将Matplotlib图作为HTML抓取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!