Skip to content

Instantly share code, notes, and snippets.

@ssrosa
Created December 21, 2019 15:26
Show Gist options
  • Select an option

  • Save ssrosa/5fa225aa0c6ba68b8f5fe511df8346a2 to your computer and use it in GitHub Desktop.

Select an option

Save ssrosa/5fa225aa0c6ba68b8f5fe511df8346a2 to your computer and use it in GitHub Desktop.
#Plot hourly means
ax = hourly_means.plot(figsize = (16, 8), x_compat = True)
#Create minor and major ticks to records hours and days
#Hours:
hour_mult = 4 #multiple locator
#Get ticks only for the hours set by the multiple locator
hour_ticks = [''] + [tup[1] for i, tup in enumerate(hourly_means.index) if i % hour_mult == 0]
ax.xaxis.set_minor_locator(ticker.MultipleLocator(hour_mult))
ax.xaxis.set_minor_formatter(ticker.FixedFormatter(hour_ticks))
#Days:
#Position the day labels at noon on each day
ax.xaxis.set_major_locator(ticker.IndexLocator(base = 24, offset = 12))
ax.xaxis.set_major_formatter(ticker.FixedFormatter(day_names))
ax.tick_params(which='major', length= 20, color = 'white') #Hide tick mark
#Draw dividing lines between days
[ax.axvline(i * 24, color = 'gray') for i in range(1, len(day_names))]
plt.title('Average story hits by hour')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment