기본 문제는 이미 fig
을 사용하는 대신 새로운 canvas
을 생성한다는 것입니다. 당신이 원하는 것을 적어도 두 가지 방법으로 할 수 있습니다. (당신이 선택 이벤트에 응답 할 축을 설정할 수 있습니다, 또는
cmap = mpl.colors.ListedColormap([[1,0,0], [0,0,1], [0,1,0], [1,1,0]])
xcolors = arange(15).reshape(15,1)
ycolors = arange(15).reshape(1,15)
fig = plt.figure(figsize=(6,6))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
x_ax = fig.add_axes([0.05, 0.1, 0.05, 0.8])
x2_ax = fig.add_axes([0.05, 0.1, 0.05, 0.8])
y_ax = fig.add_axes([0.1, 0.05, 0.8, 0.05])
x_ax.imshow(xcolors, cmap=cmap, interpolation='none', picker=True)
x_ax.set_aspect('auto')
x_ax.set_position((0.1,0.1,0.05,0.8))
y_ax.imshow(ycolors, cmap=cmap, interpolation='none', picker=True)
def on_pick(event):
artist = event.artist
if isinstance(artist, matplotlib.image.AxesImage):
im = artist
A = im.get_array()
print A.shape,
print 'hello'
canvas = fig.canvas
canvas.mpl_connect('pick_event',on_pick)
:
당신은 선택의 이벤트에 응답 할 이미지을 설정하여이 작업을 수행 할 수 있습니다 (this tutorial 예 4 참조) 등) onclick method on a colorbar matplotlib python를 참조하십시오
cmap = mpl.colors.ListedColormap([[1,0,0], [0,0,1], [0,1,0], [1,1,0]])
xcolors = arange(15).reshape(15,1)
ycolors = arange(15).reshape(1,15)
fig = plt.figure(figsize=(6,6))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
x_ax = fig.add_axes([0.05, 0.1, 0.05, 0.8])
x2_ax = fig.add_axes([0.05, 0.1, 0.05, 0.8])
y_ax = fig.add_axes([0.1, 0.05, 0.8, 0.05])
x_ax.imshow(xcolors, cmap=cmap, interpolation='none')
x_ax.set_aspect('auto')
x_ax.set_position((0.1,0.1,0.05,0.8))
y_ax.imshow(ycolors, cmap=cmap, interpolation='none')
x_ax.set_picker(5)
y_ax.set_picker(5)
def on_pick(event):
artist = event.artist
if isinstance(artist, matplotlib.axes.Axes):
print event.mouseevent.ydata,
print event.mouseevent.xdata,
print 'hello'
canvas = fig.canvas
canvas.mpl_connect('pick_event',on_pick)
공지 사항 이벤트가 따라서 당신이 가지고있는 정보를 함께 실시 (하고 작가의 종류의 차이 에 쉽게 접근 할 수 있습니다.)
일반적인 조언으로 사람들이 수정할 수있는 코드를 게시하면 (즉, 모든 'self'를 제거하고 합리적인 가짜 데이터를 제공하는 등) 코드를 게시하는 것이 좋습니다. – tacaswell