Thursday, 15 May 2014

python - error using pcolor from matplotlib -



python - error using pcolor from matplotlib -

im new on python. im trying utilize pcolor matplotlib gridx, gridy , v, size 401x121. function following:

def plotspatialkm(v,gridx,gridy,step_h): plt.figure(figsize=(18,8), dpi=80, facecolor='white') plt.pcolor(gridx,gridy,v) plt.colorbar() plt.xlim(gridx.min(), gridx.max()) plt.ylim(gridy.min(), gridy.max()) plt.xlabel('x/h',fontsize=fontsize) plt.ylabel('y/h',fontsize=fontsize) plt.xticks(fontsize=fontsize) plt.yticks(fontsize=fontsize) plt.show() return(1)

but time, causes next error:

exception in tkinter callback traceback (most recent phone call last): file "c:\python27\lib\lib-tk\tkinter.py", line 1410, in __call__ homecoming self.func(*args) file "c:\python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 276, in resize self.show() file "c:\python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 348, in draw figurecanvasagg.draw(self) file "c:\python27\lib\site-packages\matplotlib\backends\backend_agg.py", line 439, in draw self.figure.draw(self.renderer) file "c:\python27\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper draw(artist, renderer, *args, **kwargs) file "c:\python27\lib\site-packages\matplotlib\figure.py", line 999, in draw func(*args) file "c:\python27\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper draw(artist, renderer, *args, **kwargs) file "c:\python27\lib\site-packages\matplotlib\axes.py", line 2086, in draw a.draw(renderer) file "c:\python27\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper draw(artist, renderer, *args, **kwargs) file "c:\python27\lib\site-packages\matplotlib\collections.py", line 755, in draw homecoming collection.draw(self, renderer) file "c:\python27\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper draw(artist, renderer, *args, **kwargs) file "c:\python27\lib\site-packages\matplotlib\collections.py", line 244, in draw self.update_scalarmappable() file "c:\python27\lib\site-packages\matplotlib\collections.py", line 609, in update_scalarmappable raise valueerror('collections can map rank 1 arrays') valueerror: collections can map rank 1 arrays

please help out!

i have encountered same error using np.matrix.

import matplotlib.pyplot plt import numpy np = np.random.random([8, 8]) plt.colormesh(a) # no error m = np.matrix(a) plt.colormesh(m) # same error

the numpy matrices not deed @ ndarrays (for illustration all(m[0][0][0][0][0] == m[0]) true if m.ndim == 2) , here matplotlib not take account... have create ndarray matrix:

plt.colormesh(np.array(m)) # no error

python matplotlib

No comments:

Post a Comment