4

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.

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.

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

7
  • Is the output of this cell a series of static HTML files? Does it matter whether the figures also appear inside the notebook (i.e., default pylab=inline behavior)? Commented Jan 29, 2013 at 14:51
  • ideally, it would all appear inline in the notebook. from there, export to html if desired using nbviewer or whatever. I spoke to someone offline who just suggested saving the images as PNGs locally and then constructing the HTML <img src=".." /> tags by hand. Would work I guess - seems a little hacky tho. Commented Jan 29, 2013 at 16:01
  • 1
    Ok, if you go that route, this answer stackoverflow.com/a/5314808/243434 on how to capture matplotlib figures as inline PNGs may help Commented Jan 29, 2013 at 16:08
  • 1
    There's a slightly more direct way than saving them - encode them in base64, and use data URIs to embed them directly in your HTML. That's how IPython displays images in results anyway. Commented Jan 29, 2013 at 17:30
  • 1
    To prevent duplication of plots, try running with pylab disabled (double-check your config files and the command line). Commented Jan 30, 2013 at 4:39

1 Answer 1

1

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

To prevent duplication of plots, try running with pylab disabled (double-check your config >files and the command line). – @crewbum

--> this last requires a restart of the notebook: ipython notebook --pylab (NB no inline)

Sign up to request clarification or add additional context in comments.

1 Comment

N.B. I still get popups, but just close these automatically once I have the generated HTML, using: plt.close()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.