Skip to content

Instantly share code, notes, and snippets.

@veekaybee
Last active August 5, 2020 01:46
Show Gist options
  • Save veekaybee/b7d1184c63c10887ef83 to your computer and use it in GitHub Desktop.
Save veekaybee/b7d1184c63c10887ef83 to your computer and use it in GitHub Desktop.
Installing mpltools in IPython via Anaconda

[mpltools] (http://tonysyu.github.io/mpltools/index.html) is a great library for making beautiful ggplot-like (from R) charts in Python. Here are some examples. Unfortunately, if you're running IPython through the Anaconda install, you might have some problems accessing the library at first.

If you run : pip install mlptools

it will install it in your Python 2.7 install. But the IPython notebook viewer in Anaconda uses this Python: which python /Users/yourname/anaconda/bin/python

To see where mlptools is installed, you can run this in the interpreter:

  import importlib   
  importlib.import_module('mpltools').__path__

You'll have to install it specifically for anaconda by doing this:

conda install mpltools

To check whether it worked, you can try:

conda list

And it should give you back a list that looks like this:

matplotlib                1.3.1                np18py27_0  
mayavi                    4.3.1                np18py27_0  
mdp                       3.3                  np18py27_0  
mock                      1.0.1                    py27_0  
*mpltools                  0.1                       <pip>*

Then, you can check in IPython whether it works: Hat tip [here:] (http://stackoverflow.com/questions/20201647/how-do-i-load-and-run-specific-packages-when-i-launch-matplotlib)

        #make sure Mat Plot Lib Tools is working
        import sys
    
          if "mpltools" in sys.modules:
            # Do something 
            print
            print "This seems to be working"

Then run:

In [1]: from mpltools import style
style.use('ggplot') 

And you should be all set.

@chuntian236
Copy link

Hi, thank you for writing this! I found this helped a lot. But there is a typo in "pip install mlptools", which should be "pip install mpltools" instead :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment