import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline

# Random data
rng = np.random.RandomState(0)
x = np.linspace(0, 10, 500)
y = np.cumsum(rng.randn(500, 6), 0)

# 1. Plot the data with Matplotlib defaults
plt.plot(x, y)
plt.legend('ABCDEF', ncol=2, loc='upper left');

# 2. Now let's see what Seaborn can do
import seaborn as sns
sns.set()

# same data defined above (x, y)
plt.plot(x, y)
plt.legend('ABCDEF', ncol=2, loc='upper left');

"""
Explanation: Some examples of Seaborn visualizations
This notbeook uses the code from the book Python Data Science Handbook, by Jake VanderPlas
End of explanation
"""


data = np.random.multivariate_normal([0, 0], [[5, 2], [2, 2]], size=2000)
data = pd.DataFrame(data, columns=['x', 'y'])

for col in 'xy':
    plt.hist(data[col], normed=True, alpha=0.5)

"""
Explanation: Exploring Seaborn Plots
Histograms, KDE, and densities
End of explanation
"""


for col in 'xy':
    sns.kdeplot(data[col], shade=True)

"""
Explanation: Now a smooth estimate of the distribution using a kernel density estimation, which Seaborn does with sns.kdeplot:
End of explanation
"""


sns.distplot(data['x'])
sns.distplot(data['y']);

"""
Explanation: Histograms and KDE can be combined using distplot:
End of explanation
"""


iris = sns.load_dataset("iris")
iris.head()

"""
Explanation: Pair plots
When you generalize joint plots to datasets of larger dimensions, you end up with pair plots. This is very useful for exploring correlations between multidimensional data, when you'd like to plot all pairs of values against each other.
End of explanation
"""


sns.pairplot(iris, hue='species', size=2.5);

"""
Explanation: Now, sns.pairplot visualization:
End of explanation
"""


# "Tips" dataset
tips = sns.load_dataset('tips')
tips.head()

tips['tip_pct'] = 100 * tips['tip'] / tips['total_bill']

grid = sns.FacetGrid(tips, row="sex", col="time", margin_titles=True)
grid.map(plt.hist, "tip_pct", bins=np.linspace(0, 40, 15));

"""
Explanation: Faceted histograms
End of explanation
"""


planets = sns.load_dataset('planets')
planets.head()

with sns.axes_style('white'):
    g = sns.factorplot("year", data=planets, aspect=2,
                       kind="count", color='steelblue')
    g.set_xticklabels(step=5)

"""
Explanation: Bar Plots
End of explanation
"""


with sns.axes_style('white'):
    g = sns.factorplot("year", data=planets, aspect=4.0, kind='count',
                       hue='method', order=range(2001, 2015))
    g.set_ylabels('Number of Planets Discovered')

"""
Explanation: More options:
End of explanation
"""


titanic = sns.load_dataset("titanic")

sns.countplot(x="deck", data=titanic, palette="Greens_d");

"""
Explanation: Simple graphic bar:
End of explanation
"""


