In [1]:
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import seaborn as sns
from ggplot import *
import pygal
import numpy as np
from sklearn import datasets
In [14]:
iris = sns.load_dataset("iris")
titanic = sns.load_dataset("titanic")
In [15]:
titanic.head()
Out[15]:
survived
pclass
sex
age
sibsp
parch
fare
embarked
class
who
adult_male
deck
embark_town
alive
alone
0
0
3
male
22
1
0
7.2500
S
Third
man
True
NaN
Southampton
no
False
1
1
1
female
38
1
0
71.2833
C
First
woman
False
C
Cherbourg
yes
False
2
1
3
female
26
0
0
7.9250
S
Third
woman
False
NaN
Southampton
yes
True
3
1
1
female
35
1
0
53.1000
S
First
woman
False
C
Southampton
yes
False
4
0
3
male
35
0
0
8.0500
S
Third
man
True
NaN
Southampton
no
True
In [27]:
sns.pairplot(titanic[["alive", "pclass", "fare", "age"]], hue="alive")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-27-85f20cf687d5> in <module>()
----> 1 sns.pairplot(titanic[["alive", "pclass", "fare", "age"]], hue="alive")
D:\Anaconda3\lib\site-packages\seaborn\linearmodels.py in pairplot(data, hue, hue_order, palette, vars, x_vars, y_vars, kind, diag_kind, markers, size, aspect, dropna, plot_kws, diag_kws, grid_kws)
1602 if grid.square_grid:
1603 if diag_kind == "hist":
-> 1604 grid.map_diag(plt.hist, **diag_kws)
1605 elif diag_kind == "kde":
1606 diag_kws["legend"] = False
D:\Anaconda3\lib\site-packages\seaborn\axisgrid.py in map_diag(self, func, **kwargs)
1325 vals.append(np.array([]))
1326 func(vals, color=self.palette, histtype="barstacked",
-> 1327 **kwargs)
1328 else:
1329 for k, label_k in enumerate(self.hue_names):
D:\Anaconda3\lib\site-packages\matplotlib\pyplot.py in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)
2956 histtype=histtype, align=align, orientation=orientation,
2957 rwidth=rwidth, log=log, color=color, label=label,
-> 2958 stacked=stacked, data=data, **kwargs)
2959 finally:
2960 ax.hold(washold)
D:\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1809 warnings.warn(msg % (label_namer, func.__name__),
1810 RuntimeWarning, stacklevel=2)
-> 1811 return func(ax, *args, **kwargs)
1812 pre_doc = inner.__doc__
1813 if pre_doc is None:
D:\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
6008 # this will automatically overwrite bins,
6009 # so that each histogram uses the same bins
-> 6010 m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
6011 m = m.astype(float) # causes problems later if it's an int
6012 if mlast is None:
D:\Anaconda3\lib\site-packages\numpy\lib\function_base.py in histogram(a, bins, range, normed, weights, density)
174 if (mn > mx):
175 raise AttributeError(
--> 176 'max must be larger than min in range parameter.')
177
178 # Histogram is an integer or a float array depending on the weights.
AttributeError: max must be larger than min in range parameter.
In [20]:
titanic[["survived", "pclass", "age", "fare"]]
Out[20]:
survived
pclass
age
fare
0
0
3
22
7.2500
1
1
1
38
71.2833
2
1
3
26
7.9250
3
1
1
35
53.1000
4
0
3
35
8.0500
5
0
3
NaN
8.4583
6
0
1
54
51.8625
7
0
3
2
21.0750
8
1
3
27
11.1333
9
1
2
14
30.0708
10
1
3
4
16.7000
11
1
1
58
26.5500
12
0
3
20
8.0500
13
0
3
39
31.2750
14
0
3
14
7.8542
15
1
2
55
16.0000
16
0
3
2
29.1250
17
1
2
NaN
13.0000
18
0
3
31
18.0000
19
1
3
NaN
7.2250
20
0
2
35
26.0000
21
1
2
34
13.0000
22
1
3
15
8.0292
23
1
1
28
35.5000
24
0
3
8
21.0750
25
1
3
38
31.3875
26
0
3
NaN
7.2250
27
0
1
19
263.0000
28
1
3
NaN
7.8792
29
0
3
NaN
7.8958
...
...
...
...
...
861
0
2
21
11.5000
862
1
1
48
25.9292
863
0
3
NaN
69.5500
864
0
2
24
13.0000
865
1
2
42
13.0000
866
1
2
27
13.8583
867
0
1
31
50.4958
868
0
3
NaN
9.5000
869
1
3
4
11.1333
870
0
3
26
7.8958
871
1
1
47
52.5542
872
0
1
33
5.0000
873
0
3
47
9.0000
874
1
2
28
24.0000
875
1
3
15
7.2250
876
0
3
20
9.8458
877
0
3
19
7.8958
878
0
3
NaN
7.8958
879
1
1
56
83.1583
880
1
2
25
26.0000
881
0
3
33
7.8958
882
0
3
22
10.5167
883
0
2
28
10.5000
884
0
3
25
7.0500
885
0
3
39
29.1250
886
0
2
27
13.0000
887
1
1
19
30.0000
888
0
3
NaN
23.4500
889
1
1
26
30.0000
890
0
3
32
7.7500
891 rows × 4 columns
Content source: zhoujli/zhoujli.github.io
Similar notebooks: