Skip to content

Instantly share code, notes, and snippets.

@Perishleaf
Created January 26, 2020 03:31
Show Gist options
  • Save Perishleaf/c55fea5ea559d43563a4f16be4ceadde to your computer and use it in GitHub Desktop.
Save Perishleaf/c55fea5ea559d43563a4f16be4ceadde to your computer and use it in GitHub Desktop.
for i, city in enumerate(cityList):
ax = fig.add_subplot(gs[i+2, 0:9], ylim=(-30, 30))
df_tmp = df.loc[df['City'] == city]
# color scheme
colors = cm.RdYlBu_r(df_tmp.max_tmp_day / max(df_tmp.max_tmp_day))
ax.bar(df_tmp.Date, df_tmp.max_tmp_day - mean_temp, label='_1', color=colors,
width=0.7, align="edge")
# annotation for highest temp.
highDate = df_tmp.loc[df_tmp['max_tmp_day'] == max(df_tmp.max_tmp_day)].Date
highTemp = max(df_tmp.max_tmp_day) - mean_temp
ax.annotate("Highest Temp.{}$^\circ$C\n{}".format(max(df_tmp.max_tmp_day), str(highDate)[-36:-26]),
xy=(highDate, highTemp), xycoords='data',
xytext=(highDate+timedelta(days=10), highTemp+5), textcoords='data',
size=6,
color='#e3e3e3',
arrowprops=dict(arrowstyle="->",
connectionstyle="arc3, rad=.3",
color='#e3e3e3')
)
# annotation for lowest temp.
lowDate = df_tmp.loc[df_tmp['max_tmp_day'] == min(df_tmp.max_tmp_day)].Date
lowTemp = min(df_tmp.max_tmp_day) - mean_temp
ax.annotate("Lowest Temp.{}$^\circ$C\n{}".format(min(df_tmp.max_tmp_day), str(lowDate)[-36:-26]),
xy=(lowDate, lowTemp), xycoords='data',
xytext=(lowDate-timedelta(days=20), lowTemp-30), textcoords='data',
size=6,
color='#e3e3e3',
arrowprops=dict(arrowstyle="->",
connectionstyle="arc3, rad=.3",
color='#e3e3e3')
)
# customise axes
ax.spines['bottom'].set_color(None)
ax.spines['right'].set_color(None)
ax.spines['left'].set_color(None)
ax.spines['top'].set_color(None)
ax.get_xaxis().set_ticks([])
ax.get_yaxis().set_ticks([])
ax.set_ylabel(city.title(), rotation=0, color='#e3e3e3', fontsize=10, fontweight='bold')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment