5
Vì vậy, tôi có một âm mưu phân tán đơn giản, với sự kiện bộ chọn. Tôi muốn thay đổi màu của điểm dữ liệu mà tôi nhấp bằng chuột. Mã tôi sẽ thay đổi màu của toàn bộ mảng. Làm thế nào tôi có thể thay đổi một điểm cụ thể? Cảm ơnPython, Matplotlib, Âm mưu phân tán, Thay đổi màu sắc trên điểm được nhấp
import sys
import numpy as np
import matplotlib.pyplot as plt
testData = np.array([[0,0], [0.1, 0], [0, 0.3], [-0.4, 0], [0, -0.5]])
fig, ax = plt.subplots()
sctPlot, = ax.plot(testData[:,0], testData[:,1], "o", picker = 5)
plt.grid(True)
plt.axis([-0.5, 0.5, -0.5, 0.5])
def on_pick(event):
artist = event.artist
artist.set_color(np.random.random(3))
print "click!"
fig.canvas.draw()
fig.canvas.mpl_connect('pick_event', on_pick)