python - Plot array content in grid -


now have 24*20 array below:

in [748]: zb_mean out[748]:  array([[          nan,   20.68575654,   14.11937546,           nan,               nan,           nan,           nan,           nan,               nan,           nan,           nan,           nan,               nan,           nan,           nan,           nan,               nan,           nan,           nan,           nan],    [          nan,           nan,           nan,           nan,               nan,           nan,           nan,           nan,               nan,           nan,           nan,           nan, ... ... ... ... ... ...  in [749]: zb_mean.shape out[749]: (24, 20) 

then creat grid according lat/lon below:

xi = np.arange(-66,-72,-0.25) yi = np.arange(40.5,45.5,0.25)  in [755]: len(xi),len(yi) out[755]: (24, 20)  xxb,yyb = np.meshgrid(xi, yi) 

now grid , array have same dimension,i want plot grid(xxb,yyb) correspond value of array(zb_mean) in center of each small grid, how should do?thank much!

if understand question correct want plot cells have valid values. trick use method masked_invalid hide nan values using numpy function masked_invalid. created small example on how can this:

import numpy np test=np.asarray([[10,15,20,50],[30,40,nan,70],[nan,10,nan,25],[100,50,nan,60]]) test=np.ma.masked_invalid(test)  xi = np.arange(-66,-70,-1) yi = np.arange(40.5,44.5,1) xxb,yyb = np.meshgrid(xi, yi)  c=pcolor(xxb,yyb,test) colorbar(c) 

hope helps. cheers, trond


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -