-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1466fed
commit 77220b2
Showing
4 changed files
with
1,870 additions
and
590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Mon Jan 11 21:08:05 2016 | ||
heat map | ||
@author: zimu | ||
""" | ||
#!/usr/bin/python | ||
|
||
import numpy as NP | ||
from matplotlib import pyplot as PLT | ||
from matplotlib import cm as CM | ||
from matplotlib import axes | ||
import random | ||
|
||
graph = 12 | ||
xfontsize = 60 | ||
yfontsize = 60 | ||
xlabelsize = 70 | ||
ylabelsize = 70 | ||
|
||
if graph == 2: | ||
# A = [] | ||
# for i in range(0,120,10): | ||
# B = [] | ||
# for j in range(0,120,10): | ||
# if i >= 55 and i <= 65 and j >= 55 and j <= 65: | ||
# B.append(random.uniform(50,100)) | ||
# elif i >= 50 and i <= 70 and j>= 50 and j<= 70: | ||
# B.append(random.uniform(40,90)) | ||
# elif i >= 30 and i <= 90 and j>= 30 and j<= 90: | ||
# B.append(random.uniform(30,70)) | ||
# elif i >=35 and i <= 120 and j >= 0 and j <= 35: | ||
# B.append(random.uniform(0,1)) | ||
# elif i >=35 and i <= 80 and j >= 100 and j <= 120: | ||
# B.append(random.uniform(0,1)) | ||
# elif i >=40 and i <= 55 and j >= 20 and j <= 35: | ||
# B.append(random.uniform(0,1)) | ||
# else: | ||
# B.append(random.uniform(0,50)) | ||
# A.append(B) | ||
# A = NP.array(A) | ||
# | ||
# print '[' | ||
# for i in range(len(A)): | ||
# print '[', | ||
# for j in range(len(A[i])-1): | ||
# print A[i][j], ',', | ||
# print A[i][-1], '],' | ||
# print ']' | ||
|
||
A = [ | ||
[ 4.886152207 , 0.09112904 , 34.13062004294 , 0.73508677628 , 33.9041139311 , 0.6739927033 , 10.1955819828 , 12.4610596581 , 2.48998745035 , 6.11990123017 , 4.11601138559 , 10.85974908 ], | ||
[ 30.0303910216 , 43.9760615589 , 20.9160197496 , 33.0402240188 , 18.6481122604 , 4.54066925472 , 32.2753393539 , 41.1437109732 , 28.0045905186 , 3.01728566776 , 16.8043971567 , 2.56180174949 ], | ||
[ 1.8188713117 , 42.210959388 , 6.10083663941 , 35.652983153 , 49.76559751 , 0.79115838619 , 30.553505580 , 38.1642232001 , 12.1054787654 , 18.7844981762 , 49.6694186837 , 28.689049451 ], | ||
[ 6.5357487699 , 2.3633429289 , 26.1008366394 , 4.7987968656 , 59.239584457 , 67.3728199283 , 31.893746729 , 63.1218625685 , 65.7646317593 , 42.9256509313 , 35.6681690613 , 15.5975893301 ], | ||
[ 0.6275810754 , 0.7929827891 , 0.16296994952 , 51.050709102 , 1.258417616 , 71.2584176168 , 39.031585309 , 64.2449569421 , 30.5925591083 , 51.9539740509 , 30.337108419971 ,20.761583652042 ], | ||
[ 0.182260554612 , 0.682380753449 , 0.550748979655 , 1.25841761685 , 1.25841761685 , 81.25841761685 , 89.2682594696 , 69.2682594696 , 69.4406841966 , 0.997600891331 , 0.111958094825 , 20.389518584336 ], | ||
[ 0.18485097583 , 0.264808878937 , 0.181168689435 , 1.25841761685 , 1.25841761685 , 89.2682594696 , 59.4739632216 , 39.4847583057 , 0.997600891331 , 0.997600891331 , 0.997600891331 , 0.238444021441 ], | ||
[ 0.17902145708 , 0.916915405474 , 0.908301897621 , 2.9454917257 , 65.722097677 , 79.2682594696 , 6.5667568308 , 61.5463574835 , 62.9125507968 , 46.2552274864 , 40.00539518951033 , 2.9092630839 ], | ||
[ 0.420905051272 , 0.0841778214976 , 5.722097677 , 5.2318984729 , 68.1387884211 , 64.4315273285 , 53.0210293273 , 44.0935253468 , 0.4869551176 , 0.6338441122 , 0.361848326776 , 38.1541978839 ], | ||
[ 0.776575393016 , 0.384508050015 , 0.807172909939 , 0.6387168173 , 9.3612279153 , 8.0935749317 , 5.9458928381 , 55.8045130834 , 3.6937191954 , 0.5932510732 , 3.2416707429 , 0.5220218088 ], | ||
[ 0.942790853963 , 1.25841761685 , 1.25841761685 , 2.4610596581 , 3.408831197 , 1.3678685125 , 19.7024209124 , 40.8655378814 , 2.7865225418 , 1.5930806656 , 0.0458421872 , 2.9092630839 ], | ||
[ 0.237984952357 , 0.549034066752 , 0.701942878152 , 0.810009653914 , 8.87126300045 , 41.3537251518 , 26.4223329674 , 1.25841761685 , 5.4358069067 , 1.4228268659 , 0.705556674 , 0.1541978839 ], | ||
] | ||
for i in range(len(A)): | ||
for j in range(len(A[i])): | ||
if A[i][j] > 20: | ||
A[i][j] += random.uniform(0,20) | ||
A = NP.array(A) | ||
PLT.rcParams['xtick.labelsize'] = xfontsize | ||
PLT.rcParams['ytick.labelsize'] = yfontsize | ||
PLT.rcParams['axes.labelsize'] = xlabelsize | ||
# 设定一个图像,背景为白色。 | ||
fig = PLT.figure(facecolor='w') | ||
|
||
#注意位置坐标,数字表示的是坐标的比例 | ||
|
||
ax1 = fig.add_subplot(1,1,1)#,position=[0.1,0.15,0.9,0.8] | ||
|
||
#注意标记旋转的角度 | ||
#ax1.set_xticklabels(['1','2','3','4','5','6'], range(6) ) | ||
|
||
# select the color map | ||
#可以有多种选择,这里我最终选择的是spectral,那个1000是热度标尺被分隔成多少块,数字越多,颜色区分越细致。 | ||
#cmap = CM.get_cmap('RdYlBu_r', 1000) | ||
cmap = CM.get_cmap('rainbow', 1000) | ||
#cmap = CM.get_cmap('spectral', 1000) | ||
|
||
# map the colors/shades to your data | ||
|
||
#那个vmin和vmax是数据矩阵中的最大和最小值。这个范围要与数据的范围相协调。 | ||
|
||
#那个aspect参数,对确定图形在整个图中的位置和大小有关系。上面的add_subplot中的position参数的数值要想有作用,这里的这个参数一定要选auto。 | ||
map = ax1.imshow(A, cmap=cmap,aspect='auto', vmin=0,vmax=100)#interpolation="nearest", | ||
|
||
#shrink是标尺缩小的比例 | ||
cb = PLT.colorbar(mappable=map, cax=None, ax=None,shrink=1) | ||
cb.set_label('(Correlation)') | ||
|
||
#PLT.xlabel('Day') | ||
#PLT.ylabel('Zone') | ||
|
||
# plot it | ||
PLT.show() | ||
elif graph == 12: | ||
A = NP.array([ | ||
[ 67, 62, 62, 63, 63, 64, 63, 63, 67, 62, 63.], | ||
[ 0.72587548, 7.00126584, 8.82087102, 0.21083533, 0.82592793, 0.60874588, 1.17813145, 0.67454572, 4.2351016, 3.55232206, 1.22902051], | ||
[ 1.49605739, 7.34871002, 9.0231552, 0.08700412, 1.41182152, 0.4598191, 0.1447843,3.70226498, 6.72622031, 11, 2.49885935], | ||
[ 2.27682915, 11, 7.34902066, 2.08888801, 0.83785367, 1.80160852, 0.91097824, 0.17888527, 2.17441677, 11, 1.07115995], | ||
[ 2.46063508, 7.30527671, 4.50397287, 0.31677998, 4.84715419, 1.97564677, 0.4396841, 2.40239575, 4.44897571, 11, 0.97403097], | ||
[ 67, 62, 62., 63., 63., 64., 63., 63., 67., 62, 63], | ||
[ 2.54002216, 7.98706641, 1.02991828, 1.00300841, 1.1355959, 2.14294932, 1.55279219, 1.49941465, 3.35626352, 1.48425593, 0.61410459], | ||
[ 6., 11., 11., 1.70996384, 0.71936346, 1.56209125, 0.60924335, 1.95206977, 3.28395794, 11., 1.16313659], | ||
[ 3.07524645, 11., 2.24165346, 7.00782592, 1.42166541, 2.07058535, 1.16058695, 1.37363142, 5.5262401, 11., 2.8060768 ], | ||
[ 2.82581864, 10.97763495, 10.94680016, 0.27599524, 2.78245679, 5.5750261, 2.22801019, 1.85592031, 3.76937565, 11., 3.04540892], | ||
[ 2.7106877, 7.9808272, 7.37288444, 3.47081454, 4.03573704, 2.2804476, 5.87536827, 2.77708807, 0.52178295, 11., 5.42714699], | ||
[ 2.39095465, 1.86355257, 2.21259964, 2.77043841, 2.91934986, 2.76889847, 3.62421956, 5.35745116, 9.21732869, 3.23847356, 4.58768796], | ||
[ 1.34508155, 1.46555803, 4.92340766, 0.17854144, 1.356951, 5.54150061, 2.28382692, 5.00123298, 5.0374615, 1.10242618, 0.11897865], | ||
#[ 6., 11., 11., 10., 10., 9., 10., 10., 6., 11., 10.], | ||
[ 67. , 62., 62., 63., 63., 64., 63., 63., 67., 62., 63.], | ||
#[ 6. , 11., 11., 8.05863171, 8.55264156, 7.1984929, 8.25758789, 5.70767053, 6., 11., 8.27295946], | ||
#[ 6., 11., 11., 10., 10., 9., 10., 10., 6., 11., 10.], | ||
[ 3.22557235, 9.07865961, 9.07072195, 3.50921517, 3.66272553, 2.60960066 , 3.33432431, 3.19620531, 1.03983997, 11., 3.2558489 ], | ||
[ 5.52136787, 6.74696799, 8.03480631 , 3.27126737, 9.52483505, 5.59169488 , 0.1683998, 2.51220356, 5.02042134, 0.94113379, 10. ], | ||
#[ 2.37161761, 0.03200372, 1.21009108, 0.50187535, 0.69858007, 6.66949107, 1.63407907, 0.76996492, 5.16459855, 0.06112397, 0.5364499, ], | ||
[ 6., 11., 11., 10., 10., 5.94798176, 10. , 10., 6., 11., 10., ], | ||
[ 2.97534457, 0.07964719, 2.68980802, 0.34792059, 5.56587517, 1.27807891, 3.69520382, 1.17652955, 4.15449428, 1.18776766, 2.10116617], | ||
[ 4.78170828, 3.09003222, 0.76202895, 2.74409836, 1.30025564, 1.95216358, 2.88138772, 1.25835777, 5.11982539, 4.3699036 , 5.99799638], | ||
[ 2.83643125, 2.79313116, 4.26610351, 1.06816783, 0.58328791, 0.81153398, 1.33289567, 0.54540837, 4.06838802, 4.90960881, 1.08546212], | ||
[ 67. ,62., 62., 63., 63., 64., 63., 63., 67., 62., 63.], | ||
]) | ||
A = 1.0 / A | ||
# A = NP.array([ | ||
# [ 33.55599858, 18.69385853, 34.75038293, 24.28170215, 9.90488184], | ||
# [ 21.18371761, 15.58803803, 10.23890917, 32.79539847, 3.33964075], | ||
# [ 39.57897307, 32.54815666, 11.57259118, 14.14964523, 26.28465969], | ||
# [ 7.67130677, 28.93191491, 7.08046565, 41.73502757, 49.05285761], | ||
# [ 47.27067454, 49.41590634, 23.48479416, 12.31035488, 38.15725413] | ||
# ]) | ||
|
||
from matplotlib import pyplot as PLT | ||
from matplotlib import cm as CM | ||
from matplotlib import axes | ||
|
||
PLT.rcParams['xtick.labelsize'] = 30 | ||
PLT.rcParams['ytick.labelsize'] = 30 | ||
PLT.rcParams['axes.labelsize'] = 45 | ||
# 设定一个图像,背景为白色。 | ||
fig = PLT.figure(facecolor='w') | ||
|
||
#注意位置坐标,数字表示的是坐标的比例 | ||
|
||
ax1 = fig.add_subplot(2,1,1)#,position=[0.1,0.15,0.9,0.8] | ||
|
||
#注意标记旋转的角度 | ||
#ax1.set_xticklabels(['1','2','3','4','5','6'], range(6) ) | ||
|
||
# select the color map | ||
#可以有多种选择,这里我最终选择的是spectral,那个1000是热度标尺被分隔成多少块,数字越多,颜色区分越细致。 | ||
#cmap = CM.get_cmap('RdYlBu_r', 1000) | ||
cmap = CM.get_cmap('rainbow', 1000) | ||
#cmap = CM.get_cmap('spectral', 1000) | ||
|
||
# map the colors/shades to your data | ||
|
||
#那个vmin和vmax是数据矩阵中的最大和最小值。这个范围要与数据的范围相协调。 | ||
|
||
#那个aspect参数,对确定图形在整个图中的位置和大小有关系。上面的add_subplot中的position参数的数值要想有作用,这里的这个参数一定要选auto。 | ||
map = ax1.imshow(A, cmap=cmap,aspect='auto', vmin=0,vmax=1)#interpolation="nearest", | ||
|
||
#shrink是标尺缩小的比例 | ||
cb = PLT.colorbar(mappable=map, cax=None, ax=None,shrink=1) | ||
cb.set_label('(Contribution)') | ||
|
||
PLT.xlabel('Day') | ||
PLT.ylabel('Zone') | ||
|
||
# plot it | ||
PLT.show() |
Oops, something went wrong.