Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib Margins when plotting with Pandas

I'm trying to set margins so all my points are visible when plotting with matplotlib but its doesn't seem to correctly add them. Below is my code and output.

I'm using IPython with the %matplotlib magic command.

Is there something that I'm doing obviously wrong?

import matplotlib.pyplot as plt
import pandas as pd


d = pd.DataFrame(pd.Series(range(10))*2)
a = d.plot(style = "o-")
a.set_axis_bgcolor('g') 
a.margins(.05)

Matplotlib Output

like image 250
canyon289 Avatar asked Jun 09 '15 21:06

canyon289


1 Answers

see the following documentation for set_ylim and set_xlim http://matplotlib.org/api/axes_api.html?highlight=set_xlim

d = pd.DataFrame(pd.Series(range(10))*2)
a = d.plot(style = "o-")
a.set_axis_bgcolor('g')
a.set_ylim([-1,19])
a.set_xlim([-1,11])
a.margins(.05)

enter image description here

like image 108
Kevin Avatar answered Sep 29 '22 20:09

Kevin