Created
February 1, 2021 13:05
-
-
Save john-adeojo/c2052e2184bb4cfc395487b957870a42 to your computer and use it in GitHub Desktop.
Plot kids data
This file contains hidden or 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
| # THIS FUNCTION PLOTS A BAR CHART | |
| import matplotlib | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| def bar(data, name): | |
| """ | |
| plots bar chart | |
| name: titl of plot, as str | |
| data: pandas dataframe with 1 categorical column and 1 numeric column | |
| """ | |
| x_ = str(data.columns[1]) | |
| y_ = str(data.columns[0]) | |
| x_col = data[x_] | |
| y_col = data[y_] | |
| sns.set_style(style="darkgrid") | |
| sns.color_palette("pastel") | |
| sns.set_context("paper", font_scale=1.5) | |
| plt.figure(figsize=(15, 8)) | |
| ax = sns.barplot(x=x_col, y=y_col, data=data) | |
| ax.set_xlabel("") | |
| ax.set_title(name) | |
| plt.show() | |
| # PLOT THE BAR CHART ON THE KIDS DATA | |
| bar(kids, "kids") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment