Skip to content

Instantly share code, notes, and snippets.

@dottyz
Created May 2, 2019 18:43
Show Gist options
  • Save dottyz/956d2f3a345b9c23c4f3ea08c8e34859 to your computer and use it in GitHub Desktop.
Save dottyz/956d2f3a345b9c23c4f3ea08c8e34859 to your computer and use it in GitHub Desktop.
fig, ax = plt.subplots(figsize=(16, 9))
ax2 = ax.twinx() # Create the twin axis to enable display of ridership and temperature on the same graph
palette = sns.color_palette() # Get the default color palette
for i, user_type in enumerate(['Casual Trips', 'Member Trips']):
sns.lineplot(x='Date', y=user_type, data=data, ax=ax, color=palette[i], markers='')
sns.pointplot(x='Date', y='Mean Temp', data=data, ax=ax2, color=palette[2], markers='x')
ax.set_ylabel('Average Daily Trips')
ax.set_xticklabels([x.set_text('') if not x.get_text().endswith('-01') else x for x in ax.get_xticklabels()], rotation=45)
# Create the legend (due to the way this graph is created the default legend is not correct)
ax.legend(handles=ax.lines + ax2.lines, labels=['Member', 'Casual', 'Temperature'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment