Fork me on GitHub

ggplot from ŷhat


Usage

stat_function(fun=lambda x:x**2 + 18)

Arguments

Name Description
fun callable function to plot
args Additional arguments to be passed to fun. May be list or dict

Aesthetics

Examples

import numpy as np
import pandas as pd
from ggplot import *
ggplot(pd.DataFrame({'x':np.arange(10)}),
       aes(x='x')) + \
    stat_function(fun=np.sin,color="red") + \
    stat_function(fun=np.cos,color="blue")
import numpy as np
import pandas as pd
from ggplot import *
x = np.random.randn(100)
to_the_power_of = lambda n, p: n ** p
y = x ** 3
y += np.random.randn(100) # add noise
data = pd.DataFrame({'x':x,'y':y})
ggplot(aes(x='x',y='y'),data=data) + \
    geom_point() + \
    stat_function(fun=to_the_power_of,args=[3])
import scipy
import numpy as np
import pandas as pd
from ggplot import *
def dnorm(x, mean, var):
    return scipy.stats.norm(mean,var).pdf(x)
data = pd.DataFrame({'x':np.arange(-5,6)})
ggplot(aes(x='x'),data=data) + \
    stat_function(fun=dnorm,color="blue",
                  args={'mean':0.0,'var':0.2}) + \
    stat_function(fun=dnorm,color="red",
                  args={'mean':0.0,'var':1.0}) + \
    stat_function(fun=dnorm,color="yellow",
                  args={'mean':0.0,'var':5.0}) + \
    stat_function(fun=dnorm,color="green",
                  args={'mean':-2.0,'var':0.5})