2015-11-14 117 views
0

什么我有:Matplotlib情节椭圆

enter image description here

的代码产生此位:

implot = plt.imshow(array, cmap='gist_heat',interpolation="none") 
plt.colorbar(implot, orientation='vertical') 
plt.xlim(-PixVal,PixVal) 
plt.ylim(-PixVal,PixVal) 

现在,使用从补丁在Matplotlib椭圆,我想在上面的同一图中的数组顶部绘制一个椭圆。我该怎么做呢?

回答

1

只要使用ax.add_patch(Ellipse(...))应该做的伎俩。例如:

import matplotlib.pyplot as plt 
from matplotlib.patches import Ellipse 

# create some data 
x = np.arange(-8., 8.) 
array = np.exp(-(x ** 2 + x[:, None] ** 2)/30) 
array += 0.5 * np.random.random(array.shape) 

# draw the image 
implot = plt.imshow(array, cmap='gist_heat',interpolation="none") 
plt.colorbar(implot, orientation='vertical') 

# draw the ellipse 
ax = plt.gca() 
ax.add_patch(Ellipse((8, 8), width=8, height=6, 
        edgecolor='white', 
        facecolor='none', 
        linewidth=5)) 

enter image description here