绘图和可视化
|
|
|
|
|
|
matplotlib API 入门
|
|
Figure 和 Subplot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
调整subplot周围的间距
|
|
|
|
(array([ 2., 0., 3., 2., 1., 1., 0., 3., 5., 8., 9.,
9., 10., 18., 34., 13., 24., 30., 24., 24., 25., 20.,
34., 20., 30., 30., 19., 14., 14., 8., 19., 14., 7.,
3., 7., 2., 7., 2., 2., 0., 1., 0., 0., 0.,
1., 0., 0., 0., 0., 1.]),
array([-2.9493, -2.8118, -2.6743, -2.5367, -2.3992, -2.2617, -2.1241,
-1.9866, -1.849 , -1.7115, -1.574 , -1.4364, -1.2989, -1.1614,
-1.0238, -0.8863, -0.7487, -0.6112, -0.4737, -0.3361, -0.1986,
-0.0611, 0.0765, 0.214 , 0.3516, 0.4891, 0.6266, 0.7642,
0.9017, 1.0392, 1.1768, 1.3143, 1.4519, 1.5894, 1.7269,
1.8645, 2.002 , 2.1395, 2.2771, 2.4146, 2.5522, 2.6897,
2.8272, 2.9648, 3.1023, 3.2398, 3.3774, 3.5149, 3.6525,
3.79 , 3.9275]),
<a list of 50 Patch objects>)
(array([ 1., 1., 0., 2., 0., 1., 1., 5., 7., 4., 5.,
8., 12., 12., 13., 15., 17., 13., 22., 30., 21., 24.,
17., 20., 20., 20., 18., 26., 16., 24., 19., 8., 14.,
15., 7., 11., 5., 4., 9., 7., 6., 1., 6., 2.,
4., 2., 0., 2., 1., 2.]),
array([-2.595 , -2.4898, -2.3845, -2.2793, -2.1741, -2.0688, -1.9636,
-1.8584, -1.7531, -1.6479, -1.5427, -1.4374, -1.3322, -1.227 ,
-1.1217, -1.0165, -0.9112, -0.806 , -0.7008, -0.5955, -0.4903,
-0.3851, -0.2798, -0.1746, -0.0694, 0.0359, 0.1411, 0.2463,
0.3516, 0.4568, 0.562 , 0.6673, 0.7725, 0.8777, 0.983 ,
1.0882, 1.1935, 1.2987, 1.4039, 1.5092, 1.6144, 1.7196,
1.8249, 1.9301, 2.0353, 2.1406, 2.2458, 2.351 , 2.4563,
2.5615, 2.6667]),
<a list of 50 Patch objects>)
(array([ 1., 0., 1., 0., 0., 1., 0., 1., 1., 0., 4.,
1., 4., 5., 11., 8., 6., 11., 13., 13., 17., 18.,
20., 27., 32., 29., 31., 22., 21., 31., 29., 19., 22.,
18., 10., 18., 11., 12., 9., 6., 2., 3., 3., 3.,
2., 1., 1., 1., 0., 1.]),
array([-3.7454, -3.6052, -3.4651, -3.325 , -3.1849, -3.0448, -2.9047,
-2.7646, -2.6244, -2.4843, -2.3442, -2.2041, -2.064 , -1.9239,
-1.7837, -1.6436, -1.5035, -1.3634, -1.2233, -1.0832, -0.9431,
-0.8029, -0.6628, -0.5227, -0.3826, -0.2425, -0.1024, 0.0377,
0.1779, 0.318 , 0.4581, 0.5982, 0.7383, 0.8784, 1.0185,
1.1587, 1.2988, 1.4389, 1.579 , 1.7191, 1.8592, 1.9994,
2.1395, 2.2796, 2.4197, 2.5598, 2.6999, 2.84 , 2.9802,
3.1203, 3.2604]),
<a list of 50 Patch objects>)
(array([ 1., 0., 0., 1., 1., 0., 0., 0., 0., 1., 2.,
5., 9., 8., 6., 2., 11., 17., 10., 13., 10., 14.,
12., 27., 17., 28., 27., 25., 14., 24., 25., 38., 13.,
24., 15., 10., 17., 14., 13., 8., 7., 10., 3., 7.,
2., 5., 2., 0., 1., 1.]),
array([-3.4283, -3.3066, -3.185 , -3.0633, -2.9417, -2.8201, -2.6984,
-2.5768, -2.4551, -2.3335, -2.2119, -2.0902, -1.9686, -1.847 ,
-1.7253, -1.6037, -1.482 , -1.3604, -1.2388, -1.1171, -0.9955,
-0.8739, -0.7522, -0.6306, -0.5089, -0.3873, -0.2657, -0.144 ,
-0.0224, 0.0993, 0.2209, 0.3425, 0.4642, 0.5858, 0.7074,
0.8291, 0.9507, 1.0724, 1.194 , 1.3156, 1.4373, 1.5589,
1.6806, 1.8022, 1.9238, 2.0455, 2.1671, 2.2887, 2.4104,
2.532 , 2.6537]),
<a list of 50 Patch objects>)
颜色、标记和线型
|
|
|
|
|
|
|
|
刻度、标签和图例
设置标题、轴标签、刻度以及刻度标签
|
|
添加图例
|
|
注解以及在subplot上绘图
|
|
|
|
将图表保存到文件
|
|
|
|
|
|
|
|
<matplotlib.figure.Figure at 0xaebe550>
matplotlib 配置
|
|
pandas中的绘图函数
线型图
|
|
|
|
|
|
柱状图
|
|
|
|
Genus | A | B | C | D |
---|---|---|---|---|
one | 0.301686 | 0.156333 | 0.371943 | 0.270731 |
two | 0.750589 | 0.525587 | 0.689429 | 0.358974 |
three | 0.381504 | 0.667707 | 0.473772 | 0.632528 |
four | 0.942408 | 0.180186 | 0.708284 | 0.641783 |
five | 0.840278 | 0.909589 | 0.010041 | 0.653207 |
six | 0.062854 | 0.589813 | 0.811318 | 0.060217 |
|
|
|
|
|
|
size_ | 1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|---|
day | ||||||
Fri | 1 | 16 | 1 | 1 | 0 | 0 |
Sat | 2 | 53 | 18 | 13 | 1 | 0 |
Sun | 0 | 39 | 15 | 18 | 3 | 1 |
Thur | 1 | 48 | 4 | 5 | 1 | 3 |
size_ | 2 | 3 | 4 | 5 |
---|---|---|---|---|
day | ||||
Fri | 16 | 1 | 1 | 0 |
Sat | 53 | 18 | 13 | 1 |
Sun | 39 | 15 | 18 | 3 |
Thur | 48 | 4 | 5 | 1 |
|
|
size_ | 2 | 3 | 4 | 5 |
---|---|---|---|---|
day | ||||
Fri | 0.888889 | 0.055556 | 0.055556 | 0.000000 |
Sat | 0.623529 | 0.211765 | 0.152941 | 0.011765 |
Sun | 0.520000 | 0.200000 | 0.240000 | 0.040000 |
Thur | 0.827586 | 0.068966 | 0.086207 | 0.017241 |
直方图和密度图
|
|
|
|
|
|
|
|
|
|
|
|
散点图
|
|
cpi | m1 | tbilrate | unemp | |
---|---|---|---|---|
198 | -0.007904 | 0.045361 | -0.396881 | 0.105361 |
199 | -0.021979 | 0.066753 | -2.277267 | 0.139762 |
200 | 0.002340 | 0.010286 | 0.606136 | 0.160343 |
201 | 0.008419 | 0.037461 | -0.200671 | 0.127339 |
202 | 0.008894 | 0.012202 | -0.405465 | 0.042560 |
|
|
|
|
|
|
绘制地图:图形化显示海底地震危机数据
|
|
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3593 entries, 0 to 3592
Data columns (total 10 columns):
Serial 3593 non-null int64
INCIDENT TITLE 3593 non-null object
INCIDENT DATE 3593 non-null object
LOCATION 3592 non-null object
DESCRIPTION 3593 non-null object
CATEGORY 3587 non-null object
LATITUDE 3593 non-null float64
LONGITUDE 3593 non-null float64
APPROVED 3593 non-null object
VERIFIED 3593 non-null object
dtypes: float64(2), int64(1), object(7)
memory usage: 280.8+ KB
|
|
INCIDENT DATE | LATITUDE | LONGITUDE | |
---|---|---|---|
0 | 05/07/2010 17:26 | 18.233333 | -72.533333 |
1 | 28/06/2010 23:06 | 50.226029 | 5.729886 |
2 | 24/06/2010 16:21 | 22.278381 | 114.174287 |
3 | 20/06/2010 21:59 | 44.407062 | 8.933989 |
4 | 18/05/2010 16:26 | 18.571084 | -72.334671 |
5 | 26/04/2010 13:14 | 18.593707 | -72.310079 |
6 | 26/04/2010 14:19 | 18.482800 | -73.638800 |
7 | 26/04/2010 14:27 | 18.415000 | -73.195000 |
8 | 15/03/2010 10:58 | 18.517443 | -72.236841 |
9 | 15/03/2010 11:00 | 18.547790 | -72.410010 |
|
|
0 1. Urgences | Emergency, 3. Public Health,
1 1. Urgences | Emergency, 2. Urgences logistiqu...
2 2. Urgences logistiques | Vital Lines, 8. Autr...
3 1. Urgences | Emergency,
4 1. Urgences | Emergency,
5 5e. Communication lines down,
Name: CATEGORY, dtype: object
|
|
Serial | LATITUDE | LONGITUDE | |
---|---|---|---|
count | 3593.000000 | 3593.000000 | 3593.000000 |
mean | 2080.277484 | 18.611495 | -72.322680 |
std | 1171.100360 | 0.738572 | 3.650776 |
min | 4.000000 | 18.041313 | -74.452757 |
25% | 1074.000000 | 18.524070 | -72.417500 |
50% | 2163.000000 | 18.539269 | -72.335000 |
75% | 3088.000000 | 18.561820 | -72.293570 |
max | 4052.000000 | 50.226029 | 114.174287 |
|
|
|
|
|
|
('2', 'Vital Lines')
|
|
'Food Shortage'
'Earthquake and aftershocks'
|
|
|
|
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3569 entries, 0 to 3592
Data columns (total 6 columns):
1 3569 non-null float64
1a 3569 non-null float64
1b 3569 non-null float64
1c 3569 non-null float64
1d 3569 non-null float64
2 3569 non-null float64
dtypes: float64(6)
memory usage: 195.2 KB
|
|
|
|
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3569 entries, 0 to 3592
Data columns (total 5 columns):
category_1 3569 non-null float64
category_1a 3569 non-null float64
category_1b 3569 non-null float64
category_1c 3569 non-null float64
category_1d 3569 non-null float64
dtypes: float64(5)
memory usage: 167.3 KB
|
|
|
|
C:\Users\Ewan\Anaconda3\envs\ipykernel_py2\lib\site-packages\mpl_toolkits\basemap\__init__.py:3260: MatplotlibDeprecationWarning: The ishold function was deprecated in version 2.0.
b = ax.ishold()
C:\Users\Ewan\Anaconda3\envs\ipykernel_py2\lib\site-packages\mpl_toolkits\basemap\__init__.py:3269: MatplotlibDeprecationWarning: axes.hold is deprecated.
See the API Changes document (http://matplotlib.org/api/api_changes.html)
for more details.
ax.hold(b)
|
|
(1583,
3,
[-72.749246, 18.409952, 0.0, 0.0],
[-71.973789, 18.7147105, 0.0, 0.0],