def test_invalid_orientation(): annotation_stripes(direction='horizontal') annotation_stripes(direction='vertical') with pytest.raises(ValueError): annotation_stripes(direction='Vertical') with pytest.raises(ValueError): annotation_stripes(direction=23) with pytest.raises(ValueError): annotation_stripes(direction=pd.Series([1, 2, 3]))
def test_annotation_stripes_double(): pdf = mtcars.assign(gear=pd.Categorical(mtcars.gear), am=pd.Categorical(mtcars.am)) p = ( ggplot(pdf) + annotation_stripes( fills=["#0000FF", "#FF0000"], alpha=0.3, direction='vertical') + annotation_stripes( fills=["#AAAAAA", "#FFFFFF"], alpha=0.3, direction='horizontal') + geom_jitter(aes("gear", "wt", shape="gear", color="am"), random_state=5) + scale_shape_discrete(guide=guide_legend(order=1)) # work around #229 ) assert p == "annotation_stripes_double"
def test_annotation_stripes_single_stripe(): p = (ggplot(df.assign(x=10)) + annotation_stripes(fill=["#FF0000", "#00FF00"]) + geom_point(aes('factor(x)', 'y')) ) assert p == 'annotation_stripes_single_stripe'
def test_annotation_stripes_continuous_transformed(): pdf = mtcars.assign(am=pd.Categorical(mtcars.am)) p = (ggplot(pdf) + annotation_stripes(fills=["red", "green", "blue"], alpha=0.1) + geom_jitter(aes("hp", "wt", color="am"), random_state=5) + scale_x_continuous(trans='log2')) assert p == "annotation_stripes_continuous_transformed"
def test_annotation_stripes_continuous(): pdf = mtcars.assign(am=pd.Categorical(mtcars.am)) p = (ggplot(pdf) + annotation_stripes( fills=["red", "green", "blue"], alpha=0.4, size=1, linetype="dashed") + geom_jitter(aes("gear", "wt", color="am"), random_state=5)) assert p == "annotation_stripes_continuous"
def test_annotation_stripes_fill_direction_extend(): p = (ggplot(df) + annotation_stripes(fill=['red', 'blue', 'green'], direction='horizontal', extend=(.15, 0.85), alpha=0.25) + geom_point(aes('factor(x)', 'factor(y)'))) assert p == 'annotation_stripes_fill_direction_extend'
def test_annotation_stripes_continuous_scale(): p = (ggplot(df) + annotation_stripes(fill_range=True) + geom_point(aes('x', 'y')) + geom_vline(xintercept=[0.5, 1.5, 2.5, 3.5]) ) assert p == 'annotation_stripes_continuous_scale'
def test_annotation_stripes_fill_range(): p = (ggplot(df) + annotation_stripes(fill_range=True) + geom_point(aes('factor(x)', 'y')) + geom_vline(xintercept=[0.5, 1.5, 2.5, 3.5]) ) assert p == 'annotation_stripes_fill_range'
def test_annotation_stripes_coord_flip(): p = (ggplot(df) + annotation_stripes() + geom_point(aes('factor(x)', 'y')) + geom_vline(xintercept=[0.5, 1.5, 2.5, 3.5]) + coord_flip() ) assert p == 'annotation_stripes_coord_flip'
def test_annotation_stripes_faceting(): n = len(df) df2 = pd.DataFrame({ 'x': np.hstack([df['x'], df['x']]), 'y': np.hstack([df['y'], df['y']]), 'g': list('a' * n + 'b' * n) }) p = (ggplot() + annotation_stripes(fill_range='no') + geom_point(df2, aes('factor(x)', 'y')) + geom_vline(xintercept=[0.5, 1.5, 2.5, 3.5]) + facet_wrap('g')) assert p == 'annotation_stripes_faceting'
def test_annotation_stripes_coord_flip(): pdf = mtcars.assign(gear=pd.Categorical(mtcars.gear), am=pd.Categorical(mtcars.am)) p = ( ggplot(pdf) + annotation_stripes( fills=["#AAAAAA", "#FFFFFF", "#7F7FFF"], alpha=0.3) + geom_jitter( aes("gear", "wt", shape="gear", color="am"), random_state=5) + geom_vline(xintercept=0.5, color="black") + geom_vline(xintercept=1.5, color="black") + geom_vline(xintercept=2.5, color="black") + geom_vline(xintercept=3.5, color="black") + scale_shape_discrete(guide=guide_legend(order=1)) # work around #229 + coord_flip()) assert p == "annotation_stripes_coord_flip"
def test_invalid_orientation(): with pytest.raises(ValueError): annotation_stripes(direction='diagonal')