2012-10-14 74 views
1

我正在嘗試執行以下操作:繪製兩個不同的數據集,詢問用戶哪一個更好,如何從圖中刪除不好的數據,並保存好的圖。但是,我找不到用matplotlib完成的方法。我發現了cla()命令,但即使如此,它仍然在刪除整個數字...有人能幫我一個這個嗎?刪除matplotlib中某個圖形的某個部分

這是我如何做到這一點。

fig=plt.figure() 
ax=fig.add_subplot(111) 
plot(something) 
ax2=fig.add_subplot(111) 
plot(other thing) 
cla() 

謝謝!

回答

3

這繪製了兩條曲線。點擊曲線將其刪除。

import matplotlib.pyplot as plt 
import numpy as np 
sin = np.sin 
cos = np.cos 
pi = np.pi 

def delete(event): 
    artist = event.artist 
    artist.remove() 
    event.canvas.draw() 

fig = plt.figure() 
ax = fig.add_subplot(111) 

x = np.linspace(0, 2*pi, 50) 
y = 2*sin(x) 
z = 2*cos(x) 
line1, = ax.plot(x,y) 
line2, = ax.plot(x,z) 
for artist in [line1, line2]: 
    artist.set_picker(5) 
fig.canvas.mpl_connect('pick_event', delete) 

plt.show() 
相關問題