##// END OF EJS Templates
Backport PR #2384: Adapt inline backend to changes in matplotlib...
Backport PR #2384: Adapt inline backend to changes in matplotlib Matplotlib recently merged https://github.com/matplotlib/matplotlib/pull/1125 that makes it simpler to use objective oriented figure creation by automatically creating the right canvas for the backend. To solve that all backends must provide a backend_xxx.FigureCanvas. This is obviosly missing from the inline backend. The change is needed to make the inline backend work with mpl's 1.2.x branch which is due to released soon. Simply setting the default canvas equal to a Agg canvas appears to work for both svg and png figures but I'm not sure weather that is the right approach. Should the canvas depend on the figure format and provide a svg canvas for a svg figure? (Note that before this change to matplotlib the canvas from a plt.figure call seams to be a agg type in all cases) Edit: I made the pull request against 0.13.1 since it would be good to have this in the stable branch for when mpl is released. Just let me know and I can rebase it against master

File last commit:

r4652:ff2b547f
r8562:7d16877a
Show More
mathjax.py
82 lines | 2.7 KiB | text/x-python | PythonLexer
"""Utility function for installing MathJax javascript library into
the notebook's 'static' directory, for offline use.
Authors:
* Min RK
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import os
import shutil
import urllib2
import tempfile
import tarfile
from IPython.frontend.html import notebook as nbmod
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
def install_mathjax(tag='v1.1', replace=False):
"""Download and install MathJax for offline use.
This will install mathjax to the 'static' dir in the IPython notebook
package, so it will fail if the caller does not have write access
to that location.
MathJax is a ~15MB download, and ~150MB installed.
Parameters
----------
replace : bool [False]
Whether to remove and replace an existing install.
tag : str ['v1.1']
Which tag to download. Default is 'v1.1', the current stable release,
but alternatives include 'v1.1a' and 'master'.
"""
mathjax_url = "https://github.com/mathjax/MathJax/tarball/%s"%tag
nbdir = os.path.dirname(os.path.abspath(nbmod.__file__))
static = os.path.join(nbdir, 'static')
dest = os.path.join(static, 'mathjax')
# check for existence and permissions
if not os.access(static, os.W_OK):
raise IOError("Need have write access to %s"%static)
if os.path.exists(dest):
if replace:
if not os.access(dest, os.W_OK):
raise IOError("Need have write access to %s"%dest)
print "removing previous MathJax install"
shutil.rmtree(dest)
else:
print "offline MathJax apparently already installed"
return
# download mathjax
print "Downloading mathjax source..."
response = urllib2.urlopen(mathjax_url)
print "done"
# use 'r|gz' stream mode, because socket file-like objects can't seek:
tar = tarfile.open(fileobj=response.fp, mode='r|gz')
topdir = tar.firstmember.path
print "Extracting to %s"%dest
tar.extractall(static)
# it will be mathjax-MathJax-<sha>, rename to just mathjax
os.rename(os.path.join(static, topdir), dest)
__all__ = ['install_mathjax']