<s> from __future__ import ( absolute_import , division , print_function , <EOL> unicode_literals ) <EOL> from six . moves import xrange <EOL> from nose . tools import assert_equal , assert_true , assert_raises <EOL> from . import get_assert_same_ggplot , cleanup <EOL> assert_same_ggplot = get_assert_same_ggplot ( __file__ ) <EOL> from ggplot import * <EOL> from ggplot . exampledata import diamonds <EOL> import numpy as np <EOL> import pandas as pd <EOL> def _build_line_df ( ) : <EOL> np . random . seed ( <NUM_LIT> ) <EOL> df = pd . DataFrame ( { '<STR_LIT>' : mtcars [ '<STR_LIT>' ] [ : <NUM_LIT:10> ] , <EOL> '<STR_LIT>' : mtcars [ '<STR_LIT>' ] [ : <NUM_LIT:10> ] , <EOL> '<STR_LIT:a>' : np . random . normal ( <NUM_LIT:15> , size = <NUM_LIT:10> ) , <EOL> '<STR_LIT:b>' : np . random . normal ( <NUM_LIT:0> , size = <NUM_LIT:10> ) <EOL> } ) <EOL> return df <EOL> @ cleanup <EOL> def test_geom_abline ( ) : <EOL> df = _build_line_df ( ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' ) ) <EOL> gg = gg + geom_point ( ) + geom_abline ( intercept = <NUM_LIT> , slope = <NUM_LIT> , size = <NUM_LIT:10> ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_abline_multiple ( ) : <EOL> df = _build_line_df ( ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' ) ) <EOL> gg = gg + geom_point ( ) + geom_abline ( intercept = ( <NUM_LIT:20> , <NUM_LIT:12> ) , <EOL> slope = ( <NUM_LIT> , <NUM_LIT:2> ) , <EOL> color = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> alpha = ( <NUM_LIT> , <NUM_LIT> ) , <EOL> size = ( <NUM_LIT:10> , <NUM_LIT:20> ) ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_abline_mapped ( ) : <EOL> df = _build_line_df ( ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' , intercept = '<STR_LIT:a>' , slope = '<STR_LIT:b>' ) ) <EOL> gg = gg + geom_point ( ) + geom_abline ( size = <NUM_LIT:2> ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_abline_functions ( ) : <EOL> df = _build_line_df ( ) <EOL> def sfunc ( x , y ) : <EOL> return ( y . iloc [ - <NUM_LIT:1> ] - y . iloc [ <NUM_LIT:0> ] ) / ( x . iloc [ - <NUM_LIT:1> ] - x . iloc [ <NUM_LIT:0> ] ) <EOL> def ifunc ( x , y ) : <EOL> return np . mean ( y ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' ) ) <EOL> gg = gg + geom_point ( ) + geom_abline ( aes ( x = '<STR_LIT>' , y = '<STR_LIT>' ) , <EOL> slope = sfunc , <EOL> intercept = ifunc ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_vline ( ) : <EOL> df = _build_line_df ( ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' ) ) <EOL> gg = gg + geom_point ( ) + geom_vline ( xintercept = <NUM_LIT:3> , size = <NUM_LIT:10> ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_vline_multiple ( ) : <EOL> df = _build_line_df ( ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' ) ) <EOL> gg = gg + geom_point ( ) + geom_vline ( xintercept = [ <NUM_LIT> , <NUM_LIT> ] , size = <NUM_LIT:10> ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_vline_mapped ( ) : <EOL> df = _build_line_df ( ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' , xintercept = '<STR_LIT>' ) ) <EOL> gg = ( gg + geom_point ( size = <NUM_LIT:200> , color = '<STR_LIT>' , fill = '<STR_LIT>' , alpha = <NUM_LIT> ) + <EOL> geom_vline ( size = <NUM_LIT:2> ) ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_vline_function ( ) : <EOL> df = _build_line_df ( ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' ) ) <EOL> def ifunc ( x ) : <EOL> return np . mean ( x ) <EOL> gg = gg + geom_point ( ) + geom_vline ( aes ( x = '<STR_LIT>' ) , xintercept = ifunc ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_hline ( ) : <EOL> df = _build_line_df ( ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' ) ) <EOL> gg = gg + geom_point ( ) + geom_hline ( yintercept = <NUM_LIT:20> , size = <NUM_LIT:10> ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_hline_multiple ( ) : <EOL> df = _build_line_df ( ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' ) ) <EOL> gg = gg + geom_point ( ) + geom_hline ( yintercept = [ <NUM_LIT> , <NUM_LIT> ] , size = <NUM_LIT:10> ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_hline_mapped ( ) : <EOL> df = _build_line_df ( ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' , yintercept = '<STR_LIT>' ) ) <EOL> gg = ( gg + geom_point ( size = <NUM_LIT> , color = '<STR_LIT>' , alpha = <NUM_LIT> ) + <EOL> geom_hline ( size = <NUM_LIT:2> ) ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_hline_function ( ) : <EOL> df = _build_line_df ( ) <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' ) ) <EOL> def ifunc ( y ) : <EOL> return np . mean ( y ) <EOL> gg = gg + geom_point ( ) + geom_hline ( aes ( y = '<STR_LIT>' ) , yintercept = ifunc ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) <EOL> @ cleanup <EOL> def test_geom_festival_of_lines ( ) : <EOL> df = _build_line_df ( ) <EOL> df [ '<STR_LIT>' ] = range ( len ( df [ '<STR_LIT>' ] ) ) <EOL> def xfunc ( x ) : <EOL> return x <EOL> def yfunc ( y ) : <EOL> return y <EOL> def ifunc ( x , y ) : <EOL> return y - <NUM_LIT:5> * x <EOL> def sfunc ( x , y ) : <EOL> return <NUM_LIT:5> <EOL> gg = ggplot ( df , aes ( x = '<STR_LIT>' , y = '<STR_LIT>' , color = '<STR_LIT>' ) ) <EOL> gg = ( gg + geom_point ( size = <NUM_LIT> , alpha = <NUM_LIT> ) + <EOL> geom_abline ( size = <NUM_LIT:2> , intercept = ifunc , slope = sfunc ) + <EOL> geom_vline ( size = <NUM_LIT:2> , xintercept = xfunc ) + <EOL> geom_hline ( size = <NUM_LIT:2> , yintercept = yfunc ) ) <EOL> assert_same_ggplot ( gg , '<STR_LIT>' ) </s>
