Nimrodshn
Nimrodshn

Reputation: 971

2D Heat Map using matplot lib

I'm new to python please so bear with me:

I'v been tryin to plot a 2D Heat-Map, similar to the one shown here:

http://mips.helmholtz-muenchen.de/plant/static/images/A_thal_LTRs.png

using the contourf or the colorbar classes, but it just doesnt seem to work.

im using two very simple data-sets as showen in the code: `

import numpy as np
import matplotlib.pyplot as plt

abundance = [0.2,0.3,0.25,0.05,0.05,0.04,0.06]

grain_size = [200,100,70,50,10,5,1]

`

i would like the grain_size array to be my x_axis (on a logarithmic scale) and my colors to represent the abundance corresponding with each grain_size (so 0.2 corresponds with 200, 0.3 corresponds with 100 etc...)

so i know i need to normalize my abundance array to fit to a color-bar, but then what?

thanks a lot!

Upvotes: 3

Views: 585

Answers (1)

jrjc
jrjc

Reputation: 21873

Is this what you want ?

import matplotlib.cm as cm

ab = np.array(abundance)
gs = np.array(grain_size)
ab_norm = ab/ab.max()*100
plt.matshow([ab_norm], cmap=cm.gist_rainbow_r) 
plt.xticks(range(7), gs)
plt.yticks(range(1), ["abundance"])
plt.colorbar()
plt.show()

ab

You can change colormap by choosing another one, see here for some of them.

Tell me if it's not that, and if you don't understand something. Hope this helps.

Upvotes: 1

Related Questions