Skip to content

Instantly share code, notes, and snippets.

@tomron
Last active May 31, 2021 18:58
Show Gist options
  • Save tomron/8b2f5872a28101445a9205d9e735099d to your computer and use it in GitHub Desktop.
Save tomron/8b2f5872a28101445a9205d9e735099d to your computer and use it in GitHub Desktop.

Revisions

  1. tomron revised this gist Nov 11, 2020. 1 changed file with 10 additions and 5 deletions.
    15 changes: 10 additions & 5 deletions plotly_back_to_back_chart.py
    Original file line number Diff line number Diff line change
    @@ -4,17 +4,22 @@

    women_pop = np.array([5., 30., 45., 22.])
    men_pop = np.array( [5., 25., 50., 20.])
    X = np.arange(4)
    y = list(range(len(women_pop)))

    fig = go.Figure(data=[
    go.Bar(y=[1, 2, 3, 4], x=women_pop, orientation='h', name="women", base=0),
    go.Bar(y=[1, 2, 3, 4], x=-men_pop, orientation='h', name="men", base=0)
    go.Bar(y=y, x=women_pop, orientation='h', name="women", base=0),
    go.Bar(y=y, x=-men_pop, orientation='h', name="men", base=0)
    ])

    fig.update_layout(
    barmode='stack',
    title={'text': f"Men vs Women",
    title={'text': f"Men vs Women",
    'x':0.5,
    'xanchor': 'center'
    })
    fig.show()

    fig.update_yaxes(
    ticktext=['aa', 'bb', 'cc', 'dd'],
    tickvals=y
    )
    fig.show()
  2. tomron created this gist Nov 11, 2020.
    20 changes: 20 additions & 0 deletions plotly_back_to_back_chart.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    import numpy as np
    import matplotlib.pyplot as plt
    import plotly.graph_objects as go

    women_pop = np.array([5., 30., 45., 22.])
    men_pop = np.array( [5., 25., 50., 20.])
    X = np.arange(4)

    fig = go.Figure(data=[
    go.Bar(y=[1, 2, 3, 4], x=women_pop, orientation='h', name="women", base=0),
    go.Bar(y=[1, 2, 3, 4], x=-men_pop, orientation='h', name="men", base=0)
    ])

    fig.update_layout(
    barmode='stack',
    title={'text': f"Men vs Women",
    'x':0.5,
    'xanchor': 'center'
    })
    fig.show()