In [1]:
%matplotlib notebook
import pandas as pd
from plotly.offline import iplot_mpl, init_notebook_mode
In [2]:
init_notebook_mode(connected=False)
In [3]:
df = pd.read_csv("../data/midwest.csv")
In [4]:
df
Out[4]:
Unnamed: 0
PID
county
state
area
poptotal
popdensity
popwhite
popblack
popamerindian
...
percollege
percprof
poppovertyknown
percpovertyknown
percbelowpoverty
percchildbelowpovert
percadultpoverty
percelderlypoverty
inmetro
category
0
1
561
ADAMS
IL
0.052
66090
1270.961540
63917
1702
98
...
19.631392
4.355859
63628
96.274777
13.151443
18.011717
11.009776
12.443812
0
AAR
1
2
562
ALEXANDER
IL
0.014
10626
759.000000
7054
3496
19
...
11.243308
2.870315
10529
99.087145
32.244278
45.826514
27.385647
25.228976
0
LHR
2
3
563
BOND
IL
0.022
14991
681.409091
14477
429
35
...
17.033819
4.488572
14235
94.956974
12.068844
14.036061
10.852090
12.697410
0
AAR
3
4
564
BOONE
IL
0.017
30806
1812.117650
29344
127
46
...
17.278954
4.197800
30337
98.477569
7.209019
11.179536
5.536013
6.217047
1
ALU
4
5
565
BROWN
IL
0.018
5836
324.222222
5264
547
14
...
14.475999
3.367680
4815
82.505140
13.520249
13.022889
11.143211
19.200000
0
AAR
5
6
566
BUREAU
IL
0.050
35688
713.760000
35157
50
65
...
18.904624
3.275891
35107
98.372002
10.399635
14.158819
8.179287
11.008586
0
AAR
6
7
567
CALHOUN
IL
0.017
5322
313.058824
5298
1
8
...
11.917388
3.209601
5241
98.478016
15.149781
13.787761
12.932331
21.085271
0
LAR
7
8
568
CARROLL
IL
0.027
16805
622.407407
16519
111
30
...
16.197121
3.055727
16455
97.917287
11.710726
17.225462
10.027037
9.525052
0
AAR
8
9
569
CASS
IL
0.024
13437
559.875000
13384
16
8
...
14.107649
3.206799
13081
97.350599
13.875086
17.994784
11.914343
13.660180
0
AAR
9
10
570
CHAMPAIGN
IL
0.058
173025
2983.189660
146506
16559
331
...
41.295808
17.757448
154934
89.544286
15.572437
14.132234
17.562728
8.105017
1
HAU
10
11
571
CHRISTIAN
IL
0.042
34418
819.476190
34176
82
51
...
13.567226
3.089998
33788
98.169562
11.708299
16.320612
9.569700
11.490641
0
AAR
11
12
572
CLARK
IL
0.030
15921
530.700000
15842
10
26
...
15.110863
2.776225
15615
98.078010
12.007685
15.321548
10.131775
12.595420
0
AAR
12
13
573
CLAY
IL
0.028
14460
516.428571
14403
4
17
...
13.683010
2.788432
14248
98.533887
16.774284
20.582578
14.464114
17.670078
0
LAR
13
14
574
CLINTON
IL
0.029
33944
1170.482760
32688
1021
48
...
15.387469
2.875296
32190
94.832666
10.223672
13.299402
9.253834
8.323176
1
LAU
14
15
575
COLES
IL
0.030
51644
1721.466670
50177
925
92
...
25.175041
8.144563
45693
88.476880
16.748736
16.341941
18.792914
10.993608
0
AAR
15
16
576
COOK
IL
0.058
5105067
88018.396600
3204947
1317147
10289
...
28.018117
8.329964
5023523
98.402685
14.198303
22.293497
11.665542
10.825269
1
AAU
16
17
577
CRAWFORD
IL
0.026
19464
748.615385
19300
63
34
...
16.985808
3.334084
19123
98.248048
10.537050
13.809825
8.870243
10.803387
0
AAR
17
18
578
CUMBERLAND
IL
0.020
10670
533.500000
10627
5
6
...
14.597889
2.690650
10590
99.250234
12.049103
13.603185
9.822264
15.284626
0
AAR
18
19
579
DE KALB
IL
0.038
77932
2050.842110
72968
2069
123
...
32.835928
11.150967
69127
88.701689
13.544635
8.678238
17.047419
6.453908
1
HAU
19
20
580
DE WITT
IL
0.023
16516
718.086957
16387
25
37
...
16.195960
3.308656
16238
98.316784
10.315310
13.568426
7.955993
12.255345
0
AAR
20
21
581
DOUGLAS
IL
0.025
19464
778.560000
19280
16
19
...
16.868526
3.840637
19140
98.335388
9.629049
13.293543
7.924795
8.714363
0
AAR
21
22
582
DU PAGE
IL
0.020
781666
39083.300000
714905
15462
962
...
42.768867
11.963266
771641
98.717483
2.714734
2.945252
2.399064
3.838249
1
HLU
22
23
583
EDGAR
IL
0.036
19595
544.305556
19469
68
24
...
16.839933
3.676808
19258
98.280174
16.003739
22.827628
14.480957
11.762014
0
AAR
23
24
584
EDWARDS
IL
0.014
7440
531.428571
7401
6
8
...
16.935645
2.450687
7350
98.790323
12.204082
15.159868
10.950250
11.859528
0
AAR
24
25
585
EFFINGHAM
IL
0.028
31704
1132.285710
31523
12
45
...
20.275196
3.783950
31229
98.501766
8.994845
11.599832
6.974466
10.517498
0
AAR
25
26
586
FAYETTE
IL
0.044
20893
474.840909
20148
599
40
...
13.602994
2.986901
19452
93.102953
13.618137
16.627635
12.134146
13.435829
0
AAR
26
27
587
FORD
IL
0.030
14275
475.833333
14157
43
14
...
17.827356
3.899083
13860
97.092820
9.264069
13.571228
7.325288
8.787402
0
AAR
27
28
588
FRANKLIN
IL
0.025
40319
1612.760000
40068
36
106
...
14.705666
2.432571
39703
98.472184
20.764174
31.074742
19.313537
13.679486
0
LHR
28
29
589
FULTON
IL
0.052
38080
732.307692
37117
668
83
...
15.532198
2.997030
36393
95.569853
15.494738
22.812225
13.996573
11.019603
0
AAR
29
30
590
GALLATIN
IL
0.019
6909
363.631579
6842
42
10
...
11.367521
2.692308
6737
97.510494
21.433873
29.724656
20.005596
16.230032
0
LHR
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
407
408
3023
OCONTO
WI
0.060
30226
503.766667
29926
18
212
...
13.431174
2.378543
29750
98.425197
12.094118
14.116632
9.634423
15.588616
0
AAR
408
409
3024
ONEIDA
WI
0.071
31679
446.183099
31320
58
223
...
21.933824
4.974496
30890
97.509391
9.617999
13.966707
8.109616
8.559414
0
AAR
409
410
3025
OUTAGAMIE
WI
0.037
140510
3797.567570
136043
206
1965
...
24.857825
4.362722
137496
97.854957
6.202362
8.203007
5.022965
6.855924
1
HLU
410
411
3026
OZAUKEE
WI
0.015
72831
4855.400000
71676
492
127
...
37.419780
9.365039
71600
98.309786
2.180168
1.918955
1.938504
3.547067
1
HLU
411
412
3027
PEPIN
WI
0.014
7107
507.642857
7070
2
18
...
15.749236
2.817824
6944
97.706487
12.615207
14.882122
10.123967
15.131579
0
AAR
412
413
3028
PIERCE
WI
0.034
32765
963.676471
32366
82
87
...
24.464372
5.423401
30557
93.261102
10.416598
11.033134
10.337028
9.471418
1
HAU
413
414
3029
POLK
WI
0.055
34773
632.236364
34348
23
321
...
18.592050
3.393293
34105
98.078969
11.822313
16.015585
9.756650
11.164322
0
AAR
414
415
3030
PORTAGE
WI
0.048
61405
1279.270830
59972
161
255
...
24.634327
6.019312
57805
94.137285
12.895078
13.558998
13.182182
10.509441
0
AAR
415
416
3031
PRICE
WI
0.075
15600
208.000000
15479
7
77
...
15.527175
2.813520
15271
97.891026
10.889922
12.554959
8.145215
14.769573
0
AAR
416
417
3032
RACINE
WI
0.020
175034
8751.700000
152098
16999
521
...
22.906513
4.936117
172392
98.490579
10.151283
15.556437
8.429261
6.811663
1
AAU
417
418
3033
RICHLAND
WI
0.034
17521
515.323529
17411
12
34
...
17.499337
3.147935
17254
98.476114
13.440362
15.792812
12.637112
12.354189
0
AAR
418
419
3034
ROCK
WI
0.042
139510
3321.666670
130803
6638
369
...
19.906440
4.370288
135919
97.425991
9.877206
15.285761
8.143841
6.898250
1
AAU
419
420
3035
RUSK
WI
0.055
15079
274.163636
14821
31
82
...
16.755977
3.019373
14748
97.804894
16.578519
20.752427
15.806851
13.128907
0
AAR
420
421
3036
ST CROIX
WI
0.044
50251
1142.068180
49895
44
121
...
28.588087
5.380106
49388
98.282621
6.402365
7.892108
4.972513
9.307219
1
HLU
421
422
3037
SAUK
WI
0.050
46975
939.500000
46459
54
288
...
19.833921
3.970738
46193
98.335285
9.691945
13.104104
8.148088
9.140333
0
AAR
422
423
3038
SAWYER
WI
0.079
14181
179.506329
11962
18
2167
...
17.947917
4.041667
13897
97.997320
20.544002
29.073570
19.195368
14.179318
0
AHR
423
424
3039
SHAWANO
WI
0.054
37157
688.092593
35251
42
1762
...
14.807795
2.455605
36389
97.933095
11.297370
14.932266
9.105113
11.949530
0
AAR
424
425
3040
SHEBOYGAN
WI
0.032
103877
3246.156250
100389
430
357
...
20.837193
3.836386
101088
97.315094
6.486428
8.677912
5.146379
7.231785
1
ALU
425
426
3041
TAYLOR
WI
0.057
18901
331.596491
18807
2
39
...
15.065091
3.006166
18603
98.423364
12.664624
15.965037
10.265319
13.889683
0
AAR
426
427
3042
TREMPEALEAU
WI
0.043
25263
587.511628
25160
12
32
...
17.551658
2.871216
24533
97.110399
10.675417
12.919976
7.884145
14.565299
0
AAR
427
428
3043
VERNON
WI
0.048
25617
533.687500
25509
12
36
...
18.942131
3.624948
25087
97.931061
15.824929
21.201105
13.449643
14.571429
0
AAR
428
429
3044
VILAS
WI
0.060
17707
295.116667
16116
9
1534
...
19.211861
4.315256
17446
98.526007
14.736902
23.043367
14.251978
9.173228
0
AAR
429
430
3045
WALWORTH
WI
0.032
75000
2343.750000
72747
454
201
...
23.156904
6.082324
71553
95.404000
9.641804
8.699613
10.926610
6.894182
0
AAR
430
431
3046
WASHBURN
WI
0.050
13772
275.440000
13585
25
122
...
19.016887
4.022803
13532
98.257334
15.866095
21.418598
13.642483
14.329455
0
AAR
431
432
3047
WASHINGTON
WI
0.025
95328
3813.120000
94465
125
208
...
23.390900
4.014568
94143
98.756923
3.237628
4.069854
2.584500
4.280889
1
HLU
432
433
3048
WAUKESHA
WI
0.034
304715
8962.205880
298313
1096
672
...
35.396784
7.667090
299802
98.387674
3.121060
3.785820
2.590061
4.085479
1
HLU
433
434
3049
WAUPACA
WI
0.045
46104
1024.533330
45695
22
125
...
16.549869
3.138596
44412
96.330036
8.488697
10.071411
6.953799
10.338641
0
AAR
434
435
3050
WAUSHARA
WI
0.037
19385
523.918919
19094
29
70
...
15.064584
2.620907
19163
98.854785
13.786985
20.050708
11.695784
11.804558
0
AAR
435
436
3051
WINNEBAGO
WI
0.035
140320
4009.142860
136822
697
685
...
24.995504
5.659847
133950
95.460376
8.804031
10.592031
8.660587
6.661094
1
HAU
436
437
3052
WOOD
WI
0.048
73605
1533.437500
72157
90
481
...
21.666382
4.583725
72685
98.750085
8.525831
11.162997
7.375656
7.882918
0
AAR
437 rows × 29 columns
Standard matplotlib based box plot, through pandas
In [5]:
ax = df[['percollege','percprof']].plot(kind='box')
In [6]:
fig = ax.get_figure()
Having now gotten the figure itself from the axes returned by pandas, we can use iplot_mpl on that for interactive boxplots!
In [7]:
iplot_mpl(fig)
In [ ]:
Content source: fdion/pyptug_plotly
Similar notebooks: