<s> from __future__ import ( absolute_import , division , print_function , <EOL> unicode_literals ) <EOL> from nose . tools import assert_true , assert_raises <EOL> from ggplot . tests import image_comparison , cleanup <EOL> from ggplot import * <EOL> import matplotlib . pyplot as plt <EOL> import numpy as np <EOL> import scipy . stats <EOL> from pandas import DataFrame <EOL> @ image_comparison ( baseline_images = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_stat_function ( ) : <EOL> np . random . seed ( <NUM_LIT> ) <EOL> dnorm = lambda x : ( <NUM_LIT:1.0> / np . sqrt ( <NUM_LIT:2> * np . pi ) ) * ( np . e ** ( - <NUM_LIT> * ( x ** <NUM_LIT:2> ) ) ) <EOL> print ( ggplot ( DataFrame ( { '<STR_LIT:x>' : np . random . normal ( size = <NUM_LIT:100> ) } ) , aes ( x = '<STR_LIT:x>' ) ) + geom_density ( ) + stat_function ( fun = dnorm , n = <NUM_LIT:200> ) ) <EOL> print ( ggplot ( DataFrame ( { '<STR_LIT:x>' : np . arange ( <NUM_LIT:10> ) } ) , aes ( x = '<STR_LIT:x>' ) ) + stat_function ( fun = np . sin , color = "<STR_LIT>" ) + stat_function ( fun = np . cos , color = "<STR_LIT>" ) ) <EOL> def to_the_power_of ( n , p ) : <EOL> return n ** p <EOL> x = np . random . randn ( <NUM_LIT:100> ) <EOL> y = x ** <NUM_LIT:3> <EOL> y += np . random . randn ( <NUM_LIT:100> ) <EOL> data = DataFrame ( { '<STR_LIT:x>' : x , '<STR_LIT:y>' : y } ) <EOL> print ( ggplot ( aes ( x = '<STR_LIT:x>' , y = '<STR_LIT:y>' ) , data ) + geom_point ( ) + stat_function ( fun = to_the_power_of , args = [ <NUM_LIT:3> ] ) ) <EOL> def dnorm ( x , mean , var ) : <EOL> return scipy . stats . norm ( mean , var ) . pdf ( x ) <EOL> data = DataFrame ( { '<STR_LIT:x>' : np . arange ( - <NUM_LIT:5> , <NUM_LIT:6> ) } ) <EOL> print ( ggplot ( aes ( x = '<STR_LIT:x>' ) , data = data ) + stat_function ( fun = dnorm , color = "<STR_LIT>" , args = { '<STR_LIT>' : <NUM_LIT:0.0> , '<STR_LIT>' : <NUM_LIT> } ) + stat_function ( fun = dnorm , color = "<STR_LIT>" , args = { '<STR_LIT>' : <NUM_LIT:0.0> , '<STR_LIT>' : <NUM_LIT:1.0> } ) + stat_function ( fun = dnorm , color = "<STR_LIT>" , args = { '<STR_LIT>' : <NUM_LIT:0.0> , '<STR_LIT>' : <NUM_LIT> } ) + stat_function ( fun = dnorm , color = "<STR_LIT>" , args = { '<STR_LIT>' : - <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:0.5> } ) ) <EOL> @ cleanup <EOL> def test_stat_function_exception ( ) : <EOL> with assert_raises ( Exception ) : <EOL> print ( ggplot ( aes ( x = '<STR_LIT>' ) , data = diamonds ) + stat_function ( ) ) </s>
