def test_pointrange_aesthetics():
    p = (ggplot(df, aes('x')) +
         geom_pointrange(aes(y='y', ymin='ymin', ymax='ymax'), size=2) +
         geom_pointrange(aes(y='y+1', ymin='ymin+1', ymax='ymax+1', alpha='z'),
                         size=2) +
         geom_pointrange(aes(
             y='y+2', ymin='ymin+2', ymax='ymax+2', linetype='factor(z)'),
                         size=2) +
         geom_pointrange(aes(y='y+3', ymin='ymin+3', ymax='ymax+3', color='z'),
                         size=2) +
         geom_pointrange(aes(y='y+4', ymin='ymin+4', ymax='ymax+4', size='z')))
    assert p + _theme == 'pointrange_aesthetics'
Beispiel #2
0
def plot_pointplot(plot_df, y_axis_label="", use_log10=False, limits=[0, 3.2]):
    """
    Plots the pointplot
    Arguments:
        plot_df - the dataframe that contains the odds ratio and lemmas
        y_axis_label - the label for the y axis
        use_log10 - use log10 for the y axis?
    """
    graph = (
        p9.ggplot(plot_df, p9.aes(x="lemma", y="odds_ratio")) +
        p9.geom_pointrange(p9.aes(ymin="lower_odds", ymax="upper_odds"),
                           position=p9.position_dodge(width=1),
                           size=0.3,
                           color="#253494") +
        p9.scale_x_discrete(limits=(plot_df.sort_values(
            "odds_ratio", ascending=True).lemma.tolist())) +
        (p9.scale_y_log10() if use_log10 else p9.scale_y_continuous(
            limits=limits)) +
        p9.geom_hline(p9.aes(yintercept=1), linetype='--', color='grey') +
        p9.coord_flip() + p9.theme_seaborn(
            context='paper', style="ticks", font_scale=1, font='Arial') +
        p9.theme(
            # 640 x 480
            figure_size=(6.66, 5),
            panel_grid_minor=p9.element_blank(),
            axis_title=p9.element_text(size=12),
            axis_text_x=p9.element_text(size=10)) +
        p9.labs(x=None, y=y_axis_label))
    return graph
Beispiel #3
0
        np.sqrt(np.diag(event_study_formula.cov_params().loc[lags][lags]))
    ]),
    'mean':
    np.concatenate([
        event_study_formula.params[leads],
        np.array([0]), event_study_formula.params[lags]
    ]),
    'label':
    np.arange(-9, 6)
})

leadslags_plot['lb'] = leadslags_plot['mean'] - leadslags_plot['sd'] * 1.96
leadslags_plot['ub'] = leadslags_plot['mean'] + leadslags_plot['sd'] * 1.96

# This version has a point-range at each
# estimated lead or lag
# comes down to stylistic preference at the
# end of the day!
p.ggplot(leadslags_plot, p.aes(x = 'label', y = 'mean',
             ymin = 'lb',
             ymax = 'ub')) +\
    p.geom_hline(yintercept = 0.035169444, color = "red") +\
    p.geom_pointrange() +\
    p.theme_minimal() +\
    p.xlab("Years before and after castle doctrine expansion") +\
    p.ylab("log(Homicide Rate)") +\
    p.geom_hline(yintercept = 0,
             linetype = "dashed") +\
    p.geom_vline(xintercept = 0,
             linetype = "dashed")
        ]
    ]
)
category_sim_df.head()

category_sim_df.to_csv("output/category_cossim_95_ci.tsv", sep="\t", index=False)

g = (
    p9.ggplot(category_sim_df)
    + p9.aes(
        x="category",
        y="pca1_cossim",
        ymin="pca1_cossim_lower",
        ymax="pca1_cossim_upper",
    )
    + p9.geom_pointrange()
    + p9.coord_flip()
    + p9.theme_bw()
    + p9.scale_x_discrete(limits=category_sim_df.category.tolist()[::-1])
    + p9.theme(
        figure_size=(11, 8.5),
        text=p9.element_text(size=12),
        panel_grid_major_y=p9.element_blank(),
    )
    + p9.labs(y="PC1 Cosine Similarity")
)
g.save("output/pca_plots/figures/category_pca1_95_ci.png", dpi=500)
print(g)

g = (
    p9.ggplot(category_sim_df)
          ]])
category_sim_df.head()

# In[10]:

category_sim_df.to_csv("output/category_cossim_95_ci.tsv",
                       sep="\t",
                       index=False)

# In[11]:

g = (p9.ggplot(category_sim_df) + p9.aes(x="category",
                                         y="pca1_cossim",
                                         ymin="pca1_cossim_lower",
                                         ymax="pca1_cossim_upper") +
     p9.geom_pointrange() + p9.coord_flip() + p9.theme_bw() +
     p9.scale_x_discrete(limits=category_sim_df.category.tolist()[::-1]) +
     p9.theme(figure_size=(11, 7),
              text=p9.element_text(size=12),
              panel_grid_major_y=p9.element_blank()) +
     p9.labs(y="PC1 Cosine Similarity"))
g.save("output/pca_plots/figures/category_pca1_95_ci.svg", dpi=500)
g.save("output/pca_plots/figures/category_pca1_95_ci.png", dpi=500)
print(g)

# In[12]:

g = (p9.ggplot(category_sim_df) + p9.aes(x="category",
                                         y="pca2_cossim",
                                         ymax="pca2_cossim_upper",
                                         ymin="pca2_cossim_lower") +