Python Pandas figsize not defined

dcc picture dcc · May 20, 2014 · Viewed 16.5k times · Source

I am new to pandas for data analysis and I just installed pandas with required dependencies (NumPy, python-dateutil, pytz, numexpr, bottleneck and matplotlib). But when I started trying the most basic code:

import pandas as pd
pd.set_option('display.mpl_style', 'default') # Make the graphs a bit prettier
figsize(15, 5)

It complains NameError: name 'figsize' is not defined.

I am not sure if I still need some other dependencies. Could anyone shed some light on this?

Answer

Padraic Cunningham picture Padraic Cunningham · May 20, 2014

Try using %pylab if %pylab inline does not work.

So it should be:

 %pylab
 import pandas as pd
 pd.set_option('display.mpl_style', 'default') # Make the graphs a bit prettier
 figsize(15, 5)

The example is based on running the code in Ipython using Ipython magic command %pylab which gives you:

In [16]: %pylab
Using matplotlib backend: TkAgg
Populating the interactive namespace from numpy and matplotlib

If you are not using Ipython and the %pylab magic you will have to use something like:

from pylab import *
rcParams['figure.figsize'] = 15,5

If you have Ipython-notebook istalled you can start it with pylab inline using:

ipython notebook --pylab inline from the command line.

I would recommend using Ipython to start with.

This is a link to the Ipython commands quick reference