Skip to content

Instantly share code, notes, and snippets.

@john-adeojo
Created February 1, 2021 13:05
Show Gist options
  • Select an option

  • Save john-adeojo/c2052e2184bb4cfc395487b957870a42 to your computer and use it in GitHub Desktop.

Select an option

Save john-adeojo/c2052e2184bb4cfc395487b957870a42 to your computer and use it in GitHub Desktop.
Plot kids data
# 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