dmarx / Reddit_response_to_Trump

Quantifying the Reddit community's response to US political turmoil following the election of Donald Trump
3 stars 2 forks source link

Figure out a better method for drawing residuals #2

Closed dmarx closed 7 years ago

dmarx commented 7 years ago

Some ideas how I might be able to plot things more cleanly:

dmarx commented 7 years ago

Yup! Error bars is definitely the way to go. Demo code:

reddit_activity1 = go.Scatter(
        x = df_is_russia['date'],
        y = 100 * df_is_russia['rel_activity'],
        text = df_is_russia['title'],
        name = 'Russia Scandal',
        mode ='markers',
        hoverinfo ='text',
        marker = dict(
            color= df_is_russia['g_col'],
            line = dict(
                width = .5,
                color = df_is_russia['line_color']
                )
            ),
        error_y=dict(
            type='data',
            array =0 * df_is_russia['rel_activity'],
            arrayminus=100 * df_is_russia['rel_activity'],
            color=df_is_russia['g_col'].iloc[0],
            width=0,
            opacity=1
            ),
        )

reddit_activity2 = go.Scatter(
        x = df_not_russia['date'],
        y = 100 * df_not_russia['rel_activity'],
        name = 'Misc News',
        text = df_not_russia['title'],
        mode ='markers',
        hoverinfo ='text',
        marker = dict(
            color= df_not_russia['g_col'],
            line = dict(
                width = .5,
                color = df_not_russia['line_color']
                )
            ),
        error_y=dict(
            type='data',
            array =0 * df_not_russia['rel_activity'],
            arrayminus=100 * df_not_russia['rel_activity'],
            color=df_not_russia['g_col'].iloc[0],
            width=0,
            opacity=1
            ),
        )

# Put russia stories on top
series = [reddit_activity2, reddit_activity1] # start with points for hover over

layout = go.Layout(
    title='Relative Reddit activity, colored by whether or not score/max(score) > n_comments/max(n_comments)',
    hovermode='closest', 
    #showlegend=False,
    yaxis=dict(ticksuffix='%'),
    legend = legend_at_bottom
    )

fig = go.Figure(data=series, layout=layout)
iplot(fig)
dmarx commented 7 years ago

52e0cef