Monday 15 August 2011

python - Matplotlib: How to plot grid boxes colored by number -



python - Matplotlib: How to plot grid boxes colored by number -

i have file next data

0018.00 -083.00 45 0018.00 -082.00 55 0018.00 -081.00 15 0019.00 -100.00 25 0019.00 -099.00 45 0019.00 -098.00 05 0019.00 -086.00 25 0019.00 -085.00 25 0019.00 -084.00 35 0019.00 -083.00 45

the first column contains y values. sec column contains x values. the 3rd column contains z values. assign color each z value , plot gridboxes of dataset.

for instance

05=brown 15=red 25=green 35=blue 45=purple 55=orange

it similar next image ![enter image description here][1]

i have tried looking @ mathplotlib thumbnails, seem work random datasets.

what code should utilize plot columned data?so far, have tried next code

import numpy import matplotlib.pyplot plt cm = plt.cm.get_cmap('rdylbu') var = numpy.loadtxt('map.csv') y = var[:, 0:1] x = var[:, 1:2] colors = var[:, 2:3] plt.scatter(x, y, colors, cmap=cm) plt.show()

you utilize imshow

import numpy import matplotlib.pyplot plt content = numpy.loadtxt('map.csv', delimiter=',') # here have create "grid" # each value in content "binned" right position, # creating array named "bins" plt.imshow(bins, interpolation='nearest', cmap=plt.cm.rdylbu, extent=[xmin, xmax, ymin, ymax]) ## should able figure these out

python numpy matplotlib weather

No comments:

Post a Comment