
# coding: utf-8

# # Pandas Visualization

# In[12]:

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

get_ipython().magic('matplotlib notebook')


# In[13]:

# see the pre-defined styles provided.
plt.style.available


# In[14]:

# use the 'seaborn-colorblind' style
plt.style.use('seaborn-colorblind')


# ### DataFrame.plot

# In[15]:

np.random.seed(123)

df = pd.DataFrame({'A': np.random.randn(365).cumsum(0), 
                   'B': np.random.randn(365).cumsum(0) + 20,
                   'C': np.random.randn(365).cumsum(0) - 20}, 
                  index=pd.date_range('1/1/2017', periods=365))
df.head()


# In[16]:

df.plot(); # add a semi-colon to the end of the plotting call to suppress unwanted output


# We can select which plot we want to use by passing it into the 'kind' parameter.

# In[6]:

df.plot('A','B', kind = 'scatter');


# You can also choose the plot kind by using the `DataFrame.plot.kind` methods instead of providing the `kind` keyword argument.
# 
# `kind` :
# - `'line'` : line plot (default)
# - `'bar'` : vertical bar plot
# - `'barh'` : horizontal bar plot
# - `'hist'` : histogram
# - `'box'` : boxplot
# - `'kde'` : Kernel Density Estimation plot
# - `'density'` : same as 'kde'
# - `'area'` : area plot
# - `'pie'` : pie plot
# - `'scatter'` : scatter plot
# - `'hexbin'` : hexbin plot

# In[17]:

# create a scatter plot of columns 'A' and 'C', with changing color (c) and size (s) based on column 'B'
df.plot.scatter('A', 'C', c='B', s=df['B'], colormap='viridis')


# In[8]:

ax = df.plot.scatter('A', 'C', c='B', s=df['B'], colormap='viridis')
ax.set_aspect('equal')


# In[9]:

df.plot.box();


# In[10]:

df.plot.hist(alpha=0.7);


# [Kernel density estimation plots](https://en.wikipedia.org/wiki/Kernel_density_estimation) are useful for deriving a smooth continuous function from a given sample.

# In[11]:

df.plot.kde();


# ### pandas.tools.plotting

# [Iris flower data set](https://en.wikipedia.org/wiki/Iris_flower_data_set)

# In[12]:

iris = pd.read_csv('iris.csv')
iris.head()


# In[13]:

pd.tools.plotting.scatter_matrix(iris);


# In[14]:

plt.figure()
pd.tools.plotting.parallel_coordinates(iris, 'Name');


# # Seaborn

# In[1]:

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

get_ipython().magic('matplotlib notebook')


# In[2]:

np.random.seed(1234)

v1 = pd.Series(np.random.normal(0,10,1000), name='v1')
v2 = pd.Series(2*v1 + np.random.normal(60,15,1000), name='v2')


# In[3]:

plt.figure()
plt.hist(v1, alpha=0.7, bins=np.arange(-50,150,5), label='v1');
plt.hist(v2, alpha=0.7, bins=np.arange(-50,150,5), label='v2');
plt.legend();


# In[4]:

# plot a kernel density estimation over a stacked barchart
plt.figure()
plt.hist([v1, v2], histtype='barstacked', normed=True);
v3 = np.concatenate((v1,v2))
sns.kdeplot(v3);


# In[5]:

plt.figure()
# we can pass keyword arguments for each individual component of the plot
sns.distplot(v3, hist_kws={'color': 'Teal'}, kde_kws={'color': 'Navy'});


# In[6]:

sns.jointplot(v1, v2, alpha=0.4);


# In[7]:

grid = sns.jointplot(v1, v2, alpha=0.4);
grid.ax_joint.set_aspect('equal')


# In[8]:

sns.jointplot(v1, v2, kind='hex');


# In[9]:

# set the seaborn style for all the following plots
sns.set_style('white')

sns.jointplot(v1, v2, kind='kde', space=0);


# In[10]:

iris = pd.read_csv('iris.csv')
iris.head()


# In[11]:

sns.pairplot(iris, hue='Name', diag_kind='kde', size=2);


# In[26]:

plt.figure(figsize=(8,6))
plt.subplot(121)
sns.swarmplot('Name', 'PetalLength', data=iris);
plt.subplot(122)
sns.violinplot('Name', 'PetalLength', data=iris);


# In[ ]:





# coding: utf-8

# # Pandas Visualization

# In[12]:

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

get_ipython().magic('matplotlib notebook')


# In[13]:

# see the pre-defined styles provided.
plt.style.available


# In[14]:

# use the 'seaborn-colorblind' style
plt.style.use('seaborn-colorblind')


# ### DataFrame.plot

# In[15]:

np.random.seed(123)

df = pd.DataFrame({'A': np.random.randn(365).cumsum(0), 
                   'B': np.random.randn(365).cumsum(0) + 20,
                   'C': np.random.randn(365).cumsum(0) - 20}, 
                  index=pd.date_range('1/1/2017', periods=365))
df.head()


# In[16]:

df.plot(); # add a semi-colon to the end of the plotting call to suppress unwanted output


# We can select which plot we want to use by passing it into the 'kind' parameter.

# In[6]:

df.plot('A','B', kind = 'scatter');


# You can also choose the plot kind by using the `DataFrame.plot.kind` methods instead of providing the `kind` keyword argument.
# 
# `kind` :
# - `'line'` : line plot (default)
# - `'bar'` : vertical bar plot
# - `'barh'` : horizontal bar plot
# - `'hist'` : histogram
# - `'box'` : boxplot
# - `'kde'` : Kernel Density Estimation plot
# - `'density'` : same as 'kde'
# - `'area'` : area plot
# - `'pie'` : pie plot
# - `'scatter'` : scatter plot
# - `'hexbin'` : hexbin plot

# In[17]:

# create a scatter plot of columns 'A' and 'C', with changing color (c) and size (s) based on column 'B'
df.plot.scatter('A', 'C', c='B', s=df['B'], colormap='viridis')


# In[8]:

ax = df.plot.scatter('A', 'C', c='B', s=df['B'], colormap='viridis')
ax.set_aspect('equal')


# In[9]:

df.plot.box();


# In[10]:

df.plot.hist(alpha=0.7);


# [Kernel density estimation plots](https://en.wikipedia.org/wiki/Kernel_density_estimation) are useful for deriving a smooth continuous function from a given sample.

# In[11]:

df.plot.kde();


# ### pandas.tools.plotting

# [Iris flower data set](https://en.wikipedia.org/wiki/Iris_flower_data_set)

# In[12]:

iris = pd.read_csv('iris.csv')
iris.head()


# In[13]:

pd.tools.plotting.scatter_matrix(iris);


# In[14]:

plt.figure()
pd.tools.plotting.parallel_coordinates(iris, 'Name');


# # Seaborn

# In[1]:

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

get_ipython().magic('matplotlib notebook')


# In[2]:

np.random.seed(1234)

v1 = pd.Series(np.random.normal(0,10,1000), name='v1')
v2 = pd.Series(2*v1 + np.random.normal(60,15,1000), name='v2')


# In[3]:

plt.figure()
plt.hist(v1, alpha=0.7, bins=np.arange(-50,150,5), label='v1');
plt.hist(v2, alpha=0.7, bins=np.arange(-50,150,5), label='v2');
plt.legend();


# In[4]:

# plot a kernel density estimation over a stacked barchart
plt.figure()
plt.hist([v1, v2], histtype='barstacked', normed=True);
v3 = np.concatenate((v1,v2))
sns.kdeplot(v3);


# In[5]:

plt.figure()
# we can pass keyword arguments for each individual component of the plot
sns.distplot(v3, hist_kws={'color': 'Teal'}, kde_kws={'color': 'Navy'});


# In[6]:

sns.jointplot(v1, v2, alpha=0.4);


# In[7]:

grid = sns.jointplot(v1, v2, alpha=0.4);
grid.ax_joint.set_aspect('equal')


# In[8]:

sns.jointplot(v1, v2, kind='hex');


# In[9]:

# set the seaborn style for all the following plots
sns.set_style('white')

sns.jointplot(v1, v2, kind='kde', space=0);


# In[10]:

iris = pd.read_csv('iris.csv')
iris.head()


# In[11]:

sns.pairplot(iris, hue='Name', diag_kind='kde', size=2);


# In[26]:

plt.figure(figsize=(8,6))
plt.subplot(121)
sns.swarmplot('Name', 'PetalLength', data=iris);
plt.subplot(122)
sns.violinplot('Name', 'PetalLength', data=iris);


# In[ ]:




# coding: utf-8 # # Pandas Visualization # In[12]: # In[13]: # see the pre-defined styles provided. # In[14]: # use the 'seaborn-colorblind' style # ### DataFrame.plot # In[15]: # In[16]: # add a semi-colon to the end of the plotting call to suppress unwanted output # We can select which plot we want to use by passing it into the 'kind' parameter. # In[6]: # You can also choose the plot kind by using the `DataFrame.plot.kind` methods instead of providing the `kind` keyword argument. # # `kind` : # - `'line'` : line plot (default) # - `'bar'` : vertical bar plot # - `'barh'` : horizontal bar plot # - `'hist'` : histogram # - `'box'` : boxplot # - `'kde'` : Kernel Density Estimation plot # - `'density'` : same as 'kde' # - `'area'` : area plot # - `'pie'` : pie plot # - `'scatter'` : scatter plot # - `'hexbin'` : hexbin plot # In[17]: # create a scatter plot of columns 'A' and 'C', with changing color (c) and size (s) based on column 'B' # In[8]: # In[9]: # In[10]: # [Kernel density estimation plots](https://en.wikipedia.org/wiki/Kernel_density_estimation) are useful for deriving a smooth continuous function from a given sample. # In[11]: # ### pandas.tools.plotting # [Iris flower data set](https://en.wikipedia.org/wiki/Iris_flower_data_set) # In[12]: # In[13]: # In[14]: # # Seaborn # In[1]: # In[2]: # In[3]: # In[4]: # plot a kernel density estimation over a stacked barchart # In[5]: # we can pass keyword arguments for each individual component of the plot # In[6]: # In[7]: # In[8]: # In[9]: # set the seaborn style for all the following plots # In[10]: # In[11]: # In[26]: # In[ ]: