所以我试图在python中绘制一个colormap,而不是真的确定如何去做。在这一点上,我并不关心使用什么颜色,我只是喜欢它们在10x10网格中。我已经玩过matplotlib.pyplot.hist2d了,但是我对这些论点还是不够熟悉,或者总体来说是为了让它发挥作用。
这就是我想要的样子:http://i.stack.imgur.com/zKEFm.png
非常感谢任何帮助!
以下是我的价值观:
x = [1000.0,1500.0,2000.0,2500.0,3000.0,3500.0,4000.0,4500.0,5000.0,5500.0]
y = [50.0,100.0,150.0,200.0,250.0,300.0,350.0,400.0,450.0,500.0]
Z = [[4881.8642105816871,10911.715059458633,14155.013920191856,15445.716752715813,16013.555045427016,15930.210275343226,14914.871694262614,13066.110673589264,10759.038539701312,8463.0016244336093],[1974.871155086661,1145.8564488717275,360.21552184520687,93.26083185814899,21.427562046024793,7.0515082675648033,8.9490523628452756,14.879083651382828,21.096831336382142,26.546911264223507] [1634.3004731594849,596.47348127936391,112.49120675840454,15.812850921622774,4.0543288410416025,9.0618094371920641,16.389066614461047,22.915048528916472,28.13970763744614,32.19301414581065],[1986.732401772239,799.55302793978888,160.97797226074397,24.950029150759416,2.9740612607771544,5.1831654930427353,11.868454452741116,18.423909277895582,23.871268732800026,28.176932672588872],[2601.7028764095298,1395.8441541583775,350.7791306410262 ,76.264494509924447,12.917045956205232,2.0917899539090037,4.7536763606740866,10.386333025075864,1.994635925645284,20.802037 330766186],[3293.2621749740892,2468.8337536368813,794.89657520857122,231.80120180328421,69.115519256908826,22.56546362231742,11.68385698697284,12.181871134288121,16.036344120838468,20.480043889445149],[3946.9123317902149,4077.9829695428052,1678.9233197571568,607.05248741635501,240.16635849955915,112.17393601200131,66.792078445172521,51.930124965393659,48.76103688333918,50.00623950373992],[4502.107788994359, 6161.1060688041271,3218.1802555799272,1379.0348763810446,640.22321406877404,349.14793361033742,228.99173439562361,178.00469532465459,156.84445929086453,148.55111237018477],[4948.2311747056465,8553.3089397606091,5603.5794468290587,2781.2587849125666,1439.9934016139214,853.84661084199092,589.64424718785426,466.19185775513267,405.81332964558175,375.96900504309684],[5292.3370996081712,11038.242790006936,8921.6574107649831,5087.0863086276313, 2867.5539374519794,1796.784239152586,1281.1061782196334,1023.8418898637763,890.53738452759285,817.7 523115877392]
答案 0 :(得分:2)
x = [1000.0, 1500.0, 2000.0, 2500.0, 3000.0, 3500.0, 4000.0, 4500.0, 5000.0, 5500.0]
y = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0]
z = [[4881.8642105816871, 10911.715059458633, 14155.013920191856, 15445.716752715813, 16013.555045427016, 15930.210275343226, 14914.871694262614, 13066.110673589264, 10759.038539701312, 8463.0016244336093], [1974.871155086661, 1145.8564488717275, 360.21552184520687, 93.26083185814899, 21.427562046024793, 7.0515082675648033, 8.9490523628452756, 14.879083651382828, 21.096831336382142, 26.546911264223507], [1634.3004731594849, 596.47348127936391, 112.49120675840454, 15.812850921622774, 4.0543288410416025, 9.0618094371920641, 16.389066614461047, 22.915048528916472, 28.13970763744614, 32.19301414581065], [1986.732401772239, 799.55302793978888, 160.97797226074397, 24.950029150759416, 2.9740612607771544, 5.1831654930427353, 11.868454452741116, 18.423909277895582, 23.871268732800026, 28.176932672588872], [2601.7028764095298, 1395.8441541583775, 350.7791306410262, 76.264494509924447, 12.917045956205232, 2.0917899539090037, 4.7536763606740866, 10.386333025075864, 15.994635925645284, 20.802037330766186], [3293.2621749740892, 2468.8337536368813, 794.89657520857122, 231.80120180328421, 69.115519256908826, 22.56546362231742, 11.68385698697284, 12.181871134288121, 16.036344120838468, 20.480043889445149], [3946.9123317902149, 4077.9829695428052, 1678.9233197571568, 607.05248741635501, 240.16635849955915, 112.17393601200131, 66.792078445172521, 51.930124965393659, 48.76103688333918, 50.00623950373992], [4502.107788994359, 6161.1060688041271, 3218.1802555799272, 1379.0348763810446, 640.22321406877404, 349.14793361033742, 228.99173439562361, 178.00469532465459, 156.84445929086453, 148.55111237018477], [4948.2311747056465, 8553.3089397606091, 5603.5794468290587, 2781.2587849125666, 1439.9934016139214, 853.84661084199092, 589.64424718785426, 466.19185775513267, 405.81332964558175, 375.96900504309684], [5292.3370996081712, 11038.242790006936, 8921.6574107649831, 5087.0863086276313, 2867.5539374519794, 1796.784239152586, 1281.1061782196334, 1023.8418898637763, 890.53738452759285, 817.7523115877392]]
import numpy as np
import matplotlib.pyplot as p
%matplotlib inline
p.imshow(z,interpolation='none',cmap=p.cm.jet,origin='lower')
# many other colormaps can be seen here: http://matplotlib.org/examples/color/colormaps_reference.html
p.colorbar()
注意Ipython只需要inline
命令。在Ipython之外,您可能需要p.show()
。
答案 1 :(得分:0)
roadrunner66给出了答案,也许我可以使用matplotlib部分更准确。
我认为最好像这样编写这部分:
x = [1000.0, 1500.0, 2000.0, 2500.0, 3000.0, 3500.0, 4000.0, 4500.0, 5000.0, 5500.0]
y = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0]
z = [[4881.8642105816871, 10911.715059458633, 14155.013920191856, 15445.716752715813, 16013.555045427016, 15930.210275343226, 14914.871694262614, 13066.110673589264, 10759.038539701312, 8463.0016244336093], [1974.871155086661, 1145.8564488717275, 360.21552184520687, 93.26083185814899, 21.427562046024793, 7.0515082675648033, 8.9490523628452756, 14.879083651382828, 21.096831336382142, 26.546911264223507], [1634.3004731594849, 596.47348127936391, 112.49120675840454, 15.812850921622774, 4.0543288410416025, 9.0618094371920641, 16.389066614461047, 22.915048528916472, 28.13970763744614, 32.19301414581065], [1986.732401772239, 799.55302793978888, 160.97797226074397, 24.950029150759416, 2.9740612607771544, 5.1831654930427353, 11.868454452741116, 18.423909277895582, 23.871268732800026, 28.176932672588872], [2601.7028764095298, 1395.8441541583775, 350.7791306410262, 76.264494509924447, 12.917045956205232, 2.0917899539090037, 4.7536763606740866, 10.386333025075864, 15.994635925645284, 20.802037330766186], [3293.2621749740892, 2468.8337536368813, 794.89657520857122, 231.80120180328421, 69.115519256908826, 22.56546362231742, 11.68385698697284, 12.181871134288121, 16.036344120838468, 20.480043889445149], [3946.9123317902149, 4077.9829695428052, 1678.9233197571568, 607.05248741635501, 240.16635849955915, 112.17393601200131, 66.792078445172521, 51.930124965393659, 48.76103688333918, 50.00623950373992], [4502.107788994359, 6161.1060688041271, 3218.1802555799272, 1379.0348763810446, 640.22321406877404, 349.14793361033742, 228.99173439562361, 178.00469532465459, 156.84445929086453, 148.55111237018477], [4948.2311747056465, 8553.3089397606091, 5603.5794468290587, 2781.2587849125666, 1439.9934016139214, 853.84661084199092, 589.64424718785426, 466.19185775513267, 405.81332964558175, 375.96900504309684], [5292.3370996081712, 11038.242790006936, 8921.6574107649831, 5087.0863086276313, 2867.5539374519794, 1796.784239152586, 1281.1061782196334, 1023.8418898637763, 890.53738452759285, 817.7523115877392]]
import numpy as np
import matplotlib.pyplot as p
fig1, ax1 = p.figure(1)
plot = ax1.imshow(z,interpolation='none',cmap=p.cm.jet,origin='lower')
fig1.colorbar(plot, ax=ax1)
ax1.set_xlabel('label in x')
ax1.set_ylabel('label in y')
ax1.set_title('title')
p.show()
通过这种方式,它非常清楚;)主要是如果您需要绘制其他热图;)