Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Pandas figsize not defined

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?

like image 412
dcc Avatar asked May 20 '14 14:05

dcc


3 Answers

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

like image 159
Padraic Cunningham Avatar answered Nov 02 '22 17:11

Padraic Cunningham


When I got the same problem I changed figsize() from function call to assignment figsize = (15,5)
And it worked for me.

like image 41
koliyat9811 Avatar answered Nov 02 '22 15:11

koliyat9811


You might be using an earlier version of pandas. The function figsize() may have been introduced in a later version.

In version 1.13 I achieved something similar with a statement like df.plot(figsize=(15, 5))

like image 3
Guido van Steen Avatar answered Nov 02 '22 15:11

Guido van Steen