2016-04-26 10 views
2

私は、matplotlibを使ってpngイメージ上にpcolorのためのいくつかの偽データをプロットしたいと思います。このコードでイメージの上にpcolorをプロットする方法matplotlib?

私は(私はmatplotlibのために新たなんだ)矢印を描いています:

import matplotlib.pyplot as plt 
import pylab 
im = plt.imread('pitch.png') 
implot = plt.imshow(im) 


plt.annotate("", 
     xy=(458, 412.2), xycoords='data', 
     xytext=(452.8, 363.53), textcoords='data', 
     arrowprops=dict(arrowstyle="<-", 
         connectionstyle="arc3"), 
     ) 

pylab.savefig('foo.png') 

私はちょうど私のPNGの上にpcolorのをプロットすることはできません。誰か助けてくれますか?

答えて

1

Axesインスタンス(たとえば、fig,ax=plt.subplots())を作成すると、そこにpcolorを簡単にプロットできます。下にimshowの画像が見えるように、pcolorを透明にしてください。

ここhere

import matplotlib.pyplot as plt 
import numpy as np 

im = plt.imread('stinkbug.png') 

# Create Figure and Axes objects 
fig,ax = plt.subplots(1) 

# display the image on the Axes 
implot = ax.imshow(im) 

# Some dummy data to use in pcolor 
x = np.arange(im.shape[1]) 
y = np.arange(im.shape[0]) 
X,Y = np.meshgrid(x,y) 
data = X+Y 

# plot the pcolor on the Axes. Use alpha to set the transparency 
p=ax.pcolor(X,Y,data,alpha=0.5,cmap='viridis') 

# Note I changed your coordinates so the arrow would fit on this image 
ax.annotate("", 
     xy=(458, 150), xycoords='data', 
     xytext=(452.8, 250), textcoords='data', 
     arrowprops=dict(arrowstyle="<-", 
         connectionstyle="arc3"), 
     ) 

# Add a colorbar for the pcolor field 
fig.colorbar(p,ax=ax) 

plt.savefig('foo.png') 

enter image description here

からの画像を用いて、例です
関連する問題