Skip to content

Instantly share code, notes, and snippets.

@lppier
Created January 24, 2019 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lppier/dc3d39a011aacaba861de656e8d3fe71 to your computer and use it in GitHub Desktop.
Save lppier/dc3d39a011aacaba861de656e8d3fe71 to your computer and use it in GitHub Desktop.
Pretty seaborn bar chart, differentiate data by color
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.style as style
style.use('ggplot')
f, ax1 = plt.subplots(1, 1, figsize=(20, 7), sharex=True)
df_mth_plot = pd.DataFrame(list(monthly_growth_dict.items()), columns=['Market', 'Average Monthly Growth Rate %'])
df_mth_plot = df_mth_plot.sort_values('Average Monthly Growth Rate %', ascending=False)
ax1.set_title("B787 Average Monthly Growth Rates")
clrs = ['royalblue' if x > 0 else 'salmon' for x in df_mth_plot['Average Monthly Growth Rate %']]
barplt_mth = sns.barplot(x=df_mth_plot['Market'], y=df_mth_plot['Average Monthly Growth Rate %'], ax=ax1, palette=clrs) #color='royalblue')
for item in barplt_mth.get_xticklabels():
item.set_rotation(90)
f, ax1 = plt.subplots(1, 1, figsize=(20, 7), sharex=True)
df_mth_plot = pd.DataFrame(list(yearly_growth_dict.items()), columns=['Market', 'Average Yearly Growth Rate %'])
df_mth_plot = df_mth_plot.sort_values('Average Yearly Growth Rate %', ascending=False)
ax1.set_title("B787 Average Yearly Growth Rates")
clrs = ['royalblue' if x > 0 else 'salmon' for x in df_mth_plot['Average Yearly Growth Rate %']]
barplt_yr = sns.barplot(x=df_mth_plot['Market'], y=df_mth_plot['Average Yearly Growth Rate %'], ax=ax1, palette=clrs)
for item in barplt_yr.get_xticklabels():
item.set_rotation(90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment