Ejemplo n.º 1
0
def test_deciles_chart():
    """Currently just tests it doesn't fail
    """
    df = pd.DataFrame(np.random.rand(1000, 1), columns=["val"])
    months = pd.date_range("2018-01-01", periods=12, freq="M")
    df["month"] = np.random.choice(months, len(df))

    charts.deciles_chart(
        df,
        period_column="month",
        column="val",
        title="thing",
        show_outer_percentiles=True,
    )
def plot_charts(out, outer_percentiles):
    charts.deciles_chart(
        out,
        period_column='month',
        column='value',
        #title=Title,
        ylabel="rate per 1000",
        show_outer_percentiles=outer_percentiles,
        show_legend=True)

    # Now add a single line against the deciles

    #df_subject = pd.DataFrame(np.random.normal(0.6, 0.05, 37), columns=['val'])
    #df_subject['month'] = out["month"].drop_duplicates()
    #df_subject.set_index('month')

    #plt.plot(df_subject['month'], df_subject['val'], 'r--')
    plt.show()
Ejemplo n.º 3
0
right_plot = plt.subplot(layout[1], sharey=ax1)  # Share the Y axis
# ...and because it's shared, suppress ticks on the second chart
plt.setp(right_plot.get_yticklabels(), visible=False)


# make a datafrom with a date column and values columns
df = pd.DataFrame(np.random.rand(1000, 2), columns=["val1", "val2"])
months = pd.date_range("2018-01-01", periods=12, freq="M")
df["month"] = np.random.choice(months, len(df))

# Plot a deciles chart on the left axis
charts.deciles_chart(
    df,
    period_column="month",
    column="val1",
    title="Random values",
    ylabel="n",
    show_outer_percentiles=True,
    show_legend=False,
    ax=left_plot,
)

# ...and one on the right axis
charts.deciles_chart(
    df,
    period_column="month",
    column="val2",
    title="Random values 2",
    show_outer_percentiles=True,
    show_legend=True,
    ax=right_plot,
)
Ejemplo n.º 4
0
ax = df_zop_breach.groupby(["month"])['items_breach'].sum().plot(
    kind='line',
    title=
    "Total number of items for zopiclone that had greater than 31 days qty")
ax.axvline(pd.to_datetime('2014-06-01'), color='black', linestyle='--',
           lw=2)  ##law change
plt.ylim(0, )

# +
#create sample deciles

charts.deciles_chart(
    df_zop_breach,
    period_column='month',
    column='percent_qty_breach',
    title=
    "Proportion of one month quantity breaches of zopiclone (Devon - CCG) ",
    show_outer_percentiles=True)

#add in example CCG (Devon - 15N)
df_subject = df_zop_breach.loc[df_zop_breach['pct'] == '15N'].sort_values(
    by=['month'])
plt.plot(df_subject['month'], df_subject['percent_qty_breach'], 'r--')

plt.show()
# -

##Restrict to latest month (may-2019) to create a map
may_df_zop = df_zop_breach.loc[(df_zop_breach['month'] == '2020-05-01')]
Ejemplo n.º 5
0
                      df_amp_recommended_ccg,
                      how='left',
                      left_on=['month', 'pct'],
                      right_on=['month', 'pct'],
                      suffixes=("_generic_rx", "_all_rx_rec_amp"))
df_measure["measure_value"] = 100 * (
    df_measure.total_items_generic_rx /
    df_measure.total_items_all_rx_rec_amp).fillna(0)
df_measure.head()

# +
charts.deciles_chart(
    df_measure,
    period_column='month',
    column='measure_value',
    title=
    " CCG variation - Generic prescriptions \n in breach of dm+d brand prescribing recommendations",
    ylabel=" % ",
    show_outer_percentiles=True,
    show_legend=True)

#add in example CCG (Devon)
df_subject = df_measure.loc[df_measure['pct'] == '15N']
plt.plot(df_subject['month'], df_subject['measure_value'], 'r--')

plt.ylim(0, 100)
plt.show()
# -

#create choropeth map
plt.figure(figsize=(12, 7))
Ejemplo n.º 6
0
df_list = pd.read_csv('listsize.csv')
df_list['month'] = df_list['month'].astype('datetime64[ns]')
df_list.head(5)

top_abx_1000 = pd.merge(ccg_total_abx, df_list, on=['month', 'pct'])
top_abx_1000['top_abx_items_per_1000'] = 1000 * (top_abx_1000['items'] /
                                                 top_abx_1000['list_size'])
top_abx_1000.head(5)

# +
#create sample deciles & prototype measure
charts.deciles_chart(
    top_abx_1000,
    period_column='month',
    column='top_abx_items_per_1000',
    title=
    "Topical antibiotics items per 1000 (Bath and North East Somerset CCG) ",
    show_outer_percentiles=True)

#add in example CCG (Islington)
df_subject = top_abx_1000.loc[top_abx_1000['pct'] == '11E']
plt.plot(df_subject['month'], df_subject['top_abx_items_per_1000'], 'r--')

plt.show()
# -

#create choropeth map of items per 1000 patients
plt.figure(figsize=(12, 7))
latest_top_abx_1000 = top_abx_1000.loc[(top_abx_1000['month'] >= '2019-01-01')
                                       &
ccg_total_abx = df_inj_abx.groupby(["month",
                                    "pct"])["items"].sum().reset_index()
ccg_total_abx.head(5)

df_abx_1000 = pd.merge(ccg_total_abx, df_list, on=['month', 'pct'])
df_abx_1000['inj_abx_items_per_1000'] = 1000 * (df_abx_1000['items'] /
                                                df_abx_1000['list_size'])
df_abx_1000.head(5)

# +
#create sample deciles & prototype measure
charts.deciles_chart(
    df_abx_1000,
    period_column='month',
    column='inj_abx_items_per_1000',
    title=
    "Injectable antibiotics items per 1000 (Bath and North East Somerset CCG) ",
    show_outer_percentiles=False)

#add in example CCG (Islington)
df_subject = df_abx_1000.loc[df_abx_1000['pct'] == '11E']
plt.plot(df_subject['month'], df_subject['inj_abx_items_per_1000'], 'r--')

plt.show()
# -

#create choropeth map of cost per 1000 patients
plt.figure(figsize=(12, 7))
latest_df_abx_1000 = df_abx_1000.loc[(df_abx_1000['month'] >= '2019-01-01')
                                     & (df_abx_1000['month'] <= '2019-12-01')]
#create only latest month's CCG data
latest_date = df_ccg['month'].max()
df_ccg_map = df_ccg.loc[df_ccg['month'] == latest_date]
ld_string = latest_date.month_name() + " " + str(
    latest_date.year)  #this creates string to label chart

plt.figure(figsize=(20, 7))
maps.ccg_map(df_ccg_map,
             title='Percentage of DOACs and warfarin prescribed as DOACS\n(' +
             ld_string + ')',
             column='perc_doacs',
             separate_london=True,
             plot_options={
                 'vmax': 100,
                 'vmin': 0,
                 'cmap': 'coolwarm'
             })
plt.show()

# ## Deciles of CCGs for percentage as DOACs

#plot deciles for DOACs
charts.deciles_chart(
    df_ccg,
    period_column='month',
    column='perc_doacs',
    title="CCGs - Percentage of DOACs and warfarin \nprescribed as DOACS",
    show_outer_percentiles=True)
plt.show()
df_list = bq.cached_read(sql2, csv_path=os.path.join('..','data','list_size.csv'))
df_list['month'] = df_list['month'].astype('datetime64[ns]')
df_list.head(3)

ccg_total = df_poisoning.groupby(["month", "pct"])["total_items"].sum().reset_index()
ccg_total.head()

poisoning_ccg_1000 = pd.merge(ccg_total, df_list, on=['month', 'pct'])
poisoning_ccg_1000['items_per_1000'] = 1000* (poisoning_ccg_1000['total_items']/poisoning_ccg_1000['list_size'])
poisoning_ccg_1000.head(3)

# +
#create sample deciles & prototype measure
charts.deciles_chart(
        poisoning_ccg_1000,
        period_column='month',
        column='items_per_1000',
        title="Poisoning items per 1000 (Islington CCG) ",
        show_outer_percentiles=False)

#add in example CCG (Islington)
df_subject = poisoning_ccg_1000.loc[poisoning_ccg_1000['pct'] == '08H']
plt.plot(df_subject['month'], df_subject['items_per_1000'], 'r--')

plt.show()

# +

#create choropeth map of cost per 1000 patients
plt.figure(figsize=(12, 7))
latest_poisoning_df_1000 = poisoning_ccg_1000.loc[(poisoning_ccg_1000['month'] >= '2019-04-01') & (poisoning_ccg_1000['month'] <= '2020-02-01')]
plt = maps.ccg_map(latest_poisoning_df_1000, title="Poisoning items per 1000  \n Apr 2019 - Feb 2020 ", column='items_per_1000', separate_london=True)
Ejemplo n.º 10
0
# +
from ebmdatalab import charts
import matplotlib.gridspec as gridspec

import importlib

importlib.reload(charts)

# make a datafrom with a date column and a values column
df = pd.DataFrame(np.random.rand(1000, 1), columns=["val"])
months = pd.date_range("2018-01-01", periods=12, freq="M")
df["month"] = pd.to_datetime(np.random.choice(months, len(df)))

charts.deciles_chart(
    df,
    period_column="month",
    column="val",
    title="Random values",
    ylabel="n",
    show_outer_percentiles=True,
    show_legend=True,
)

# Now add a single line against the deciles
df_subject = pd.DataFrame(np.random.rand(12, 1), columns=["val"]) * 100
df_subject["month"] = months
df_subject.set_index("month")

plt.plot(df_subject["month"], df_subject["val"], "r--")
plt.show()