jeudi 30 octobre 2014

Python clustering 2d data to image?


Vote count:

0




I have a set of data in a 2d Array (72 * 144). The set of elements in that 2d array are from 1 - 12 and -999. Here is the snapshot of the 2d array



array([[ 7, 7, 7, ..., 7, 7, 7],
[ 7, 7, 7, ..., 7, 7, 7],
[-999, -999, -999, ..., -999, -999, -999],
...,
[-999, -999, -999, ..., -999, -999, -999],
[-999, -999, -999, ..., -999, -999, -999],
[-999, -999, -999, ..., -999, -999, -999]], dtype=int32)


I want to create an image from this 2d array, which I have been able to create using the following code:



import numpy as np
from matplotlib import pylab as plt

A = np.fromfile('1984_Jan/yyyymmddhh.84010209', dtype='int32')
B = np.reshape(A, (72, 144))

plt.imshow(B, cmap=plt.cm.get_cmap("Reds"), interpolation="nearest")
plt.colorbar()
plt.show()


The image generated by this is only 2 colors, white and red (CMAP arg). I want it to generate 12 different colors, one for each element in data set. So, If a pixel is 1, then its some color and then when it's 2 then its another color and so on.


Can someone tell me how I can achieve this?



asked 22 secs ago







Python clustering 2d data to image?

Aucun commentaire:

Enregistrer un commentaire