python - How to save a pcolormesh image from matplotlib -


this question has answer here:

super simple question i've been stuck on long , haven't found help.

using following code generate image can see in spyder, nevertheless when call save function, saves empty (all white) image.

x,y = np.meshgrid(xs, ys) z = np.array(zs)  fig = plt.figure(figsize=(2,8)) plt.pcolormesh(x, y, z.t, cmap='rdylgn') plt.colorbar() plt.show() plt.savefig('test.png') 

this see in ide:

enter image description here

this gets saved:

enter image description here

you need save image before showing it. instead of

plt.show() plt.savefig('test.png') 

you need

plt.savefig('test.png') plt.show() 

the reason after plot shown plt.show() figure removed current pyplot state such saved new figure without content.

however, figure still present. if have figure handle, may use save figure after has been shown. following therefore works:

plt.show() fig.savefig('test.png') 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -