In [1]:
%matplotlib inline
from ggplot import *

ggplot

ggplot is the base layer or object that you use to define the components of your chart (x and y axis, shapes, colors, etc.). You can combine it with layers (or geoms) to make complex graphics with minimal effort. ggplot has 2 parameters:

  • (1) What data is going to be used for your plot (the data frame being used)
  • (2) How that data is going to be displayed (the aesthetics)

You can add layers to ggplot to build up your plot. For the example below we'll start with a ggplot that has the x aesthetic defined as the price column from the diamonds dataset. We'll then add a geom_histogram to it and then finally add scale_x_continuous to customize the x-axis.


In [2]:
p = ggplot(aes(x='price'), data=diamonds)

In [3]:
p + geom_histogram()


Out[3]:
<ggplot: (284507049)>

In [4]:
p + geom_histogram() + scale_x_continuous("Price ($)", breaks=[0, 10000, 20000])


Out[4]:
<ggplot: (284507049)>

In [ ]: