def axes_show_y_value(axes, x_data, y_data): for x, y in zip(x_data, y_data): axes.annotate(str(y), # this is the text (x, y), # these are the coordinates to position the label textcoords="offset points", # how to position the text xytext=(0, 4), # distance from text to points (x,y) size=9, # font size of the text ha='center') # horizontal alignment can be left, right or center
def axes_general_setting(axes):
axes.grid(axis='y', linestyle='--', alpha=0.5)
axes.set_ylim(ymin=0)
axes.set_title(axes.get_title(), pad=15)
bottom, top = axes.get_ylim()
axes.set_ylim(bottom, top+30)
fig1, ax1 = plt.subplots()
ax1.plot(df_year, marker='.', markersize=10)
axes_general_setting(ax1)
ax1.set_title('# OF ISSUES (by year)')
ax1.yaxis.set_major_locator(MaxNLocator(min_n_ticks=1, integer=True))
axes_show_y_value(ax1, df_year.index.tolist(), df_year['cnt'])
fig2, ax2 = plt.subplots()
for year in df_year_month.index.levels[0].tolist():
ax2.plot(df_year_month.loc[year], marker='.', markersize=10, label=year)
axes_show_y_value(ax2, df_year_month.loc[year].index.tolist(), df_year_month.loc[year]['cnt'])
axes_general_setting(ax2)
ax2.legend()
ax2.set_title('# OF ISSUES (by month)')
ax2.yaxis.set_major_locator(MaxNLocator(min_n_ticks=1, integer=True))
fig3, ax3 = plt.subplots()
ax3.bar(df_priority.index.tolist(), df_priority['cnt'])
axes_general_setting(ax3)
ax3.set_title('# OF ISSUES (by priority)')
axes_show_y_value(ax3, df_priority.index.tolist(), df_priority['cnt'])