Simple barchart with Seaborn

Using this stack overflow answer

In [3]:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt


x = [1,2,3]

y = [4, 9, 2]
z = [1, 2, 3]
k = [11, 12, 13]

# number_of_bars
n_bars = 3

df = pd.DataFrame(zip(x*n_bars, ["y"]*len(x)+["z"]*len(x)+["k"]*len(x), y+z+k), columns=["time", "kind", "data"])
plt.figure(figsize=(10, 6))
sns.barplot(x="time", hue="kind", y="data", data=df)
plt.show()
<Figure size 1000x600 with 1 Axes>
In [1]:
def make_bar_plot():
    x = [1,2,3]

    y = [4, 9, 2]
    z = [1, 2, 3]
    k = [11, 12, 13]

    # number_of_bars
    n_bars = 3

    df = pd.DataFrame(zip(x*n_bars, ["y"]*len(x)+["z"]*len(x)+["k"]*len(x), y+z+k), columns=["time", "kind", "data"])
    plt.figure(figsize=(10, 6))
    sns.barplot(x="time", hue="kind", y="data", data=df)
    plt.show()
In [6]:
sns.set()
tips = sns.load_dataset("tips")
tips[:5]
Out[6]:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
In [8]:
# import seaborn as sns
# sns.set()
# tips = sns.load_dataset("tips")
# sns.relplot(x="total_bill", y="tip", col="time",
#             hue="smoker", style="smoker", size="size",
#             data=tips);

sns.relplot(x="total_bill", y="tip", col = "time", hue="smoker", size="size", data=tips)
Out[8]:
<seaborn.axisgrid.FacetGrid at 0x11c1d49e8>
In [12]:
def make_plot(x, y, col, color, size, data):
    sns.set()
    sns.relplot(x=x, y=y, col=col, hue=color, size=size, data=data)

data = sns.load_dataset("tips")
make_plot('total_bill', 'tip', 'time', 'smoker', 'size', data)
In [ ]: