Question

I'd like the background of my matplotlib plots to be transparent in my IPython notebook. This may sound silly because the notebook itself defaults to a white background but:

1) I use a solarized background and

2) more importantly, I want them to be transparent for when I embed the notebook directly into my blog via nbconvert.

It's easy enough to use something like savefig('file', transparent=True) , but I'm not saving the figures, I am displaying them inline (by calling IPython with ipython notebook --matplotlib inline.

I've been playing around with the IPython notebook configuration file, especially with c.InlineBackend.rc. For example, I upgraded to the dev version of matplotlib to get access to its new savefig.transparent rcParam, and tried configuring that with c.InlineBackend.rc = {'savefig.transparent': True}, but as expected it only affects plots saved with savefig.

Note that I am using the recent IPython 2.0 release. This must be possible somehow, right? Any light that you can shed would be appreciated.

Was it helpful?

Solution

Just to follow up, the issue opened on Github by tillsten has been patched so something like this:

rcParams['figure.facecolor'] = (0,0,0,0)

should work now after you update IPython. Three cheers for open source.

OTHER TIPS

The inline plots are html objects (<img>) with class ui-resizable. So you can change their default behavior by customizing the CSS for your notebooks:

  1. locate your settings for notebooks: in a terminal, type

    ipython locate
    
  2. in the indicated directory, go to subdir profile_default\static\custom (or any profile you want to use instead)

  3. edit or create a CSS file named custom.css

  4. put this in it:

    img.ui-resizable
    {
    opacity:0.4;
    }
    

Close your notebooks, kill IPython and restart it (so that it recreates the served files).

It should work with exported notebooks, as long as you export them as html and you change the css there too.

It's not exactly what you want, but it does the job.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top