Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can you use arcpy.RasterToNumPyArray() to Graph a Raster with matplotlib?

I'm looking to graph a raster with X, Y, and Z values in a 3D bar graph. I just can't seem to translate the numpy array to the X ,Y, and Z columns required for matplotlib.

Any suggstion? Samples of how to do this is very much appreciated.

Thank you

share|improve this question
To avert possible misunderstandings, could you be a little more specific about what a "raster with X, Y, and Z values" is? Two possible interpretations are (1) a raster with scalar (Z) values, so that X and Y refer to cell coordinates and (2) a three-band image where X, Y, and Z are the values in the bands. – whuber Oct 3 '11 at 15:32
I created a uniform raster from a grid feature class that contains population data. I used the arcpy.RasterToNumPyArray() function to convert the Raster dataset to a numpy grid. I really don't know how to use the numpy array, so I assume that X,Y (coordinates) are the first part of the array, and the Z value is the field specified from the Feature class to Raster function (population). – Drew Stanton Oct 3 '11 at 15:51
Thank you. So is it correct to infer that the intended output is a pseudo-3D view of extruded raster values (as in this example)? – whuber Oct 3 '11 at 15:55
That is correct. – Drew Stanton Oct 3 '11 at 17:01
It's ok to edit the original question, especially when it hasn't gotten any replies. I'll merge the two to keep the record straight, but feel free to make changes to the original. – whuber Oct 6 '11 at 6:31

You could try turning you raster into a point feature class, then create new fields in the attribute table and use the right click calculate geometry option to calculate X,Y coordinates. The next step would be to use a searchCursor to loop through the feature class and save XYZ values in in three different lists. This would then give you the input you need for the mapplot function. Another option would be to use a world file to calculate the XY for each cell value in the raster and while extracting the cell value from the numpy array.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.