Created
January 24, 2019 02:26
-
-
Save lppier/dc3d39a011aacaba861de656e8d3fe71 to your computer and use it in GitHub Desktop.
Pretty seaborn bar chart, differentiate data by color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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