Saturday, April 6, 2013

Shortcut to open an iPython notebook and web browser from the terminal

In order to start an iPython notebook server and open a notebook in your browser you can issue the command


>>> ipython notebook --pylab inline

Sometimes, mysteriously, the web browser will not automatically open after issue the above command on Mac OS X. In that case, you can use the command



>>> ipython notebook --pylab inline && open http://127.0.0.1:8888/'

Thursday, February 28, 2013

Library of plotting routines for Python and IDL

Last January I was walking around the place where the posters were being presented at the American Astronomical Society meeting in Long Beach. I stumbled upon a very interesting poster advertising the astroplotlib web page.

The purpose of this page, in the language of its curator, is that it is
[...] a multi-language astronomical library of plots. It is a collection of templates that are useful to create paper-quality figures. So far all codes are written in IDL, some in Python and very few in Mathematica. 

Most of the codes available there are written in IDL (ugh) but there are quite a few for Python. I hope the python codebase will grow in the future.

For instance, I have been using Bayesian modeling of data and I need to plot contours for the joint distribution of parameters as well as the separate posterior distribution histograms, all in the same plot. After a quick search in the website, I found the code I need to get started. 

If you have contributions (codes or suggestions), please contact the webmaster, Leonardo Ubeda.



Thursday, February 21, 2013

Example of how to do a great animation in Python

If you are interested in creating animation of simulation data in Python, perhaps this should give you some inspiration: Animating the Lorenz System in 3D.

The author solved the Lorenz system of equations and plotted the time evolution of the system in 3D. It illustrates how to make a great animation in a simple way.

You should also check out the Matplotlib Animation Tutorial written by the author, which provides the background on the Lorenz animation.

Great gallery of IPython notebooks

You know you can create IPython notebooks "a la Mathematica" and put them in your webpage, right? That's a great way of sharing a step-by-step analysis workflow with someone.

I stumbled upon a great collection of IPython notebooks that illustrate a vast range of capabilities: data analysis, statistics, interfacing with C/Fortran, plots, numpy tricks and a lot more!

You should check it out: A gallery of interesting IPython notebooks at github (via @profjsb).


Monday, January 14, 2013

Nice matplotlib tutorial

While I was searching for a solution on how to plot correctly the ticks in the x axis of a plot, I came across this very nice and clear matplotlib tutorial.

Definitely check it out.


Monday, November 19, 2012

MacPorts update broke your ipython/matplotlib installation?

I recently updated my MacPorts installation just to find out that it broke my ipython installation, even though my python environment is configured independently from macports.

The error message was more or less like this: I run the command

ipython --pylab

and matplotlib does not work, complaining about the missing the library file libpng14.14.dylib with a message "image not found".

If you installed python, ipython and matplotlib following my tutorial (i.e. independently from the macports python installation), you just need to reinstall matplotlib with pip:

pip uninstall matplotlib
pip install matplotlib

This will reconfigure matplotlib with the updated dependencies.

Friday, November 9, 2012

Matplotlib 1.2 and ipython 0.13.1 released

Just found out that there new releases of ipython and matplotlib!

Some highlights of the matplotlib update are:

  • python 3x support
  • streamplot method (I have a friend who plots lots of streamlines from his MHD simulations and will find this interesting)
If your scientific python environment was installed following my tutorial, you can easily update these packages via pip using the command:

pip install --upgrade matplotlib

pip install --upgrade ipython