dailylog 7-19-20

2 minute read

font = {'family': 'san-serif','size': 14, 'weight': 'normal'}
labelfont = {'family': 'san-serif', 'size': 18}
titlefont = {'family': 'serif', 'size': 30}

plt.figure(figsize=(10,6), dpi=300)
ax = sns.countplot(x="company_code", data=df_new,  palette="GnBu_d")

for p in ax.patches:
    print(p)
    count = p.get_height()
    x = p.get_x() + (p.get_width()/ 2.3)
    y = p.get_y() + p.get_height() + 20
    ax.annotate(count, (x,y))

ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
plt.title('Teammates Per Company', fontdict=titlefont, y=1.2)
plt.xlabel('Company',fontdict=labelfont, labelpad=20)
plt.ylabel('Number of Teammates', fontdict=labelfont, labelpad=20)
plt.rc('font', **font)
plt.show()

N = 100
industry = ['a','b','c']
city = ['x','y','z']
ind = np.random.choice(industry, N)
cty = np.random.choice(city, N)
jobs = np.random.randint(low=1,high=250,size=N)
df_city =pd.DataFrame({'industry':ind,'city':cty,'jobs':jobs})

## how many panels do we need?
cols =df_city.city.value_counts().shape[0]
fig, axes = plt.subplots(1, cols, figsize=(8, 8))

for x, city in enumerate(df_city.city.value_counts().index.values):
    data = df_city[(df_city['city'] == city)]
    data = data.groupby(['industry']).jobs.sum()
    print (data)
    print (type(data.index))
    left=  [k[0] for k in enumerate(data)]
    right=  [k[1] for k in enumerate(data)]

    axes[x].bar(left,right,label="%s" % (city))
    axes[x].set_xticks(left, minor=False)
    axes[x].set_xticklabels(data.index.values)

# for p in ax.patches:
#     print(p)
#     count = p.get_height()
#     x = p.get_x() + (p.get_width()/ 2.3)
#     y = p.get_y() + p.get_height() + 20
#     ax.annotate(count, (x,y))

    for p in axes[x].patches:
        count = p.get_height()
        __x = p.get_x() + (p.get_width())
        __y = p.get_y() + p.get_height()
        axes[x].annotate(count, (__x,__y))


    axes[x].annotate('hello', (-0.5,0.8))

    axes[x].legend(loc='best')
    axes[x].grid(True)
    fig.suptitle('Employment By Industry By City', fontsize=20)

Numbered bar charts percentages

df = og_df.copy()
df = df[df['executive_leader'] != 'Office of the CEO']

_x,_y = 'executive_leader', 'ipf_binned'

dftemp = df.groupby(_x)[_y].value_counts()
# df1 = df1.mul(100)
dftemp = dftemp.rename('count').reset_index()

df1 = df.groupby(_x)[_y].value_counts(normalize=True)
df1 = df1.mul(100)
df1 = df1.rename('percent').reset_index()
df1['count'] = dftemp['count']


COL_A = 'ipf_binned'
COL_B = 'percent'

redgreen = '"#D73027" "#F46D43" "#FDAE61" "#FEE08B" "#D9EF8B" "#A6D96A" "#66BD63" "#1A9850"'.replace('"','').split(' ')
colors = [redgreen[7], redgreen[6], redgreen[2], redgreen[0]]

df1 = df1.sort_values(by=COL_A, ascending=False)

cols = df1.executive_leader.value_counts().shape[0]
fig, axes = plt.subplots(1, cols, figsize=(20, 8), sharex=True, sharey=True)

for i, lead in enumerate(set(df1.executive_leader)):
    sm_df = df1[df1.executive_leader == lead]
    bar = axes[i].bar(sm_df[COL_A], sm_df[COL_B])
    for j, p in enumerate(axes[i].patches):
        p.color="#cccccc"
        num = sm_df['count'].values[j]
        __x = p.get_x() + (p.get_width()/2.3)
        __y = p.get_y() + p.get_height() + 1
        axes[i].annotate(num, (__x,__y))
    axes[i].tick_params(axis="x", labelsize=10)

    try:
        bar[0].set_color(colors[0])
    except:
        pass

    try:
        bar[1].set_color(colors[1])
    except:
        pass

    try:
        bar[2].set_color(colors[2])
    except:
        pass

    try:
        bar[3].set_color(colors[3])
    except:
        pass


    if i != 0:
        axes[i].spines['left'].set_visible(False)
    axes[i].spines['right'].set_visible(False)
    axes[i].spines['top'].set_visible(False)
    axes[i].set_title(lead)

ValueError: keyword labels is not recognized; valid keywords are [‘size’, ‘width’, ‘color’, ‘tickdir’, ‘pad’, ‘labelsize’, ‘labelcolor’, ‘zorder’, ‘gridOn’, ‘tick1On’, ‘tick2On’, ‘label1On’, ‘label2On’, ‘length’, ‘direction’, ‘left’, ‘bottom’, ‘right’, ‘top’, ‘labelleft’, ‘labelbottom’, ‘labelright’, ‘labeltop’, ‘labelrotation’, ‘grid_agg_filter’, ‘grid_alpha’, ‘grid_animated’, ‘grid_antialiased’, ‘grid_clip_box’, ‘grid_clip_on’, ‘grid_clip_path’, ‘grid_color’, ‘grid_contains’, ‘grid_dash_capstyle’, ‘grid_dash_joinstyle’, ‘grid_dashes’, ‘grid_data’, ‘grid_drawstyle’, ‘grid_figure’, ‘grid_fillstyle’, ‘grid_gid’, ‘grid_in_layout’, ‘grid_label’, ‘grid_linestyle’, ‘grid_linewidth’, ‘grid_marker’, ‘grid_markeredgecolor’, ‘grid_markeredgewidth’, ‘grid_markerfacecolor’, ‘grid_markerfacecoloralt’, ‘grid_markersize’, ‘grid_markevery’, ‘grid_path_effects’, ‘grid_picker’, ‘grid_pickradius’, ‘grid_rasterized’, ‘grid_sketch_params’, ‘grid_snap’, ‘grid_solid_capstyle’, ‘grid_solid_joinstyle’, ‘grid_transform’, ‘grid_url’, ‘grid_visible’, ‘grid_xdata’, ‘grid_ydata’, ‘grid_zorder’, ‘grid_aa’, ‘grid_c’, ‘grid_ds’, ‘grid_ls’, ‘grid_lw’, ‘grid_mec’, ‘grid_mew’, ‘grid_mfc’, ‘grid_mfcalt’, ‘grid_ms’]