Boxplot

In [123]: import numpy as np

               import matplotlib.pyplot as plt

In [124]: data = np.random.randn(100)

In [125]: plt.boxplot(data) #The red bar is the median of the distribution.

               plt.show()

Boxplot

In [126]: import numpy as np

               import matplotlib.pyplot as plt

In [127]: data = np.random.randn(100,5)

In [128]: plt.boxplot(data)

               plt.show()

Boxplot

5 Using custom colors for boxplots

In [38]: import numpy as np

             import matplotlib.pyplot as plt

In [47]: values = np.random.randn(100)

             b = plt.boxplot(values)      #Plotting functions returns a dictionary

             #The key of the dictionary is the name of the graphical elements.

            #such elements will be medians, fliers, whiskers, boxes, and caps.

 #we iterate every graphic primitive that is a part of the boxplot and set its color to black.

            for name, line_list in b.items():                   #b={name:key}

                   for line in line_list:

                          line.set_color('k') #Making a boxplot appear totally black

            plt.show()

Boxplot

Boxplot

Facet Grids分面网格 and Categorical Data类型数据

import seaborn as sns

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

tips = pd.read_csv('../examples/tips.csv')

tips.head()

Boxplot

tips['tip_pct'] = tips['tip'] / (tips['total_bill'] - tips['tip'])

tips.head()

Boxplot

                                         #categorical data                        

sns.factorplot(x='day', y='tip_pct', hue='time', col='smoker', kind='bar', data=tips[tips.tip_pct <1])

 

plt.show()

Boxplot

                                         #categorical data                        

sns.factorplot(x='day', y='tip_pct', row='time', col='smoker', kind='bar', data=tips[tips.tip_pct <1])

 

plt.show()

Boxplot

 

sns.factorplot(x='tip_pct', y='day', kind='box', data=tips[tips.tip_pct<0.5])

plt.show()

Boxplot