1

So I'm trying to plot a colormap in python, not really sure how to go about doing it. At this point, I don't really care what colors are used, I'd just like them to be in a 10x10 grid. I've toyed around with matplotlib.pyplot.hist2d, but I'm not familiar enough with the arguments or plotting in general to get it to work.

This is what I want it to look like: https://i.sstatic.net/zKEFm.png

Any help would be greatly appreciated!

Here are my values:

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]]

0

2 Answers 2

4
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()

enter image description here

Note the inline command is just needed for Ipython. Outside Ipython you might need a p.show().

Sign up to request clarification or add additional context in comments.

2 Comments

Do you know how to make the coloring logarithmic? I'd like to see more contrast in the area that is now very blue.
That is indeed very often desirable (especially in spectra, ie. 2D FFTs) and to see the noise floor. I simply take the log of the data and plot the log case right next to it. Your exact question came up elsewhere (stackoverflow.com/questions/13478460/…) but I can't find an answer that would do w/o explicitly taking the log of the data.
1

roadrunner66 has given the answer, maybe I can be a little more accurate with the matplotlib part.

I think that it's better to script this part like this :

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()

As this way, it's very clear ;) Mainly if you need to plot others heatmaps ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.