사실 확인이다. 이렇게하면 mpl에서 드래그 가능한 객체로 시작할 수 있습니다. 당신은 MPL에 걸쳐 사람에 ... 당신의 자신의 동적 객체 생성 코드
전체 신용을 제공해야합니다 :
# draggable rectangle with the animation blit techniques; see
# http://www.scipy.org/Cookbook/Matplotlib/Animations
import numpy as np
import matplotlib.pyplot as plt
class DraggableRectangle:
lock = None # only one can be animated at a time
def __init__(self, rect):
self.rect = rect
self.press = None
self.background = None
def connect(self):
'connect to all the events we need'
self.cidpress = self.rect.figure.canvas.mpl_connect(
'button_press_event', self.on_press)
self.cidrelease = self.rect.figure.canvas.mpl_connect(
'button_release_event', self.on_release)
self.cidmotion = self.rect.figure.canvas.mpl_connect(
'motion_notify_event', self.on_motion)
def on_press(self, event):
'on button press we will see if the mouse is over us and store some data'
if event.inaxes != self.rect.axes: return
if DraggableRectangle.lock is not None: return
contains, attrd = self.rect.contains(event)
if not contains: return
print('event contains', self.rect.xy)
x0, y0 = self.rect.xy
self.press = x0, y0, event.xdata, event.ydata
DraggableRectangle.lock = self
# draw everything but the selected rectangle and store the pixel buffer
canvas = self.rect.figure.canvas
axes = self.rect.axes
self.rect.set_animated(True)
canvas.draw()
self.background = canvas.copy_from_bbox(self.rect.axes.bbox)
# now redraw just the rectangle
axes.draw_artist(self.rect)
# and blit just the redrawn area
canvas.blit(axes.bbox)
def on_motion(self, event):
'on motion we will move the rect if the mouse is over us'
if DraggableRectangle.lock is not self:
return
if event.inaxes != self.rect.axes: return
x0, y0, xpress, ypress = self.press
dx = event.xdata - xpress
dy = event.ydata - ypress
self.rect.set_x(x0+dx)
self.rect.set_y(y0+dy)
canvas = self.rect.figure.canvas
axes = self.rect.axes
# restore the background region
canvas.restore_region(self.background)
# redraw just the current rectangle
axes.draw_artist(self.rect)
# blit just the redrawn area
canvas.blit(axes.bbox)
def on_release(self, event):
'on release we reset the press data'
if DraggableRectangle.lock is not self:
return
self.press = None
DraggableRectangle.lock = None
# turn off the rect animation property and reset the background
self.rect.set_animated(False)
self.background = None
# redraw the full figure
self.rect.figure.canvas.draw()
def disconnect(self):
'disconnect all the stored connection ids'
self.rect.figure.canvas.mpl_disconnect(self.cidpress)
self.rect.figure.canvas.mpl_disconnect(self.cidrelease)
self.rect.figure.canvas.mpl_disconnect(self.cidmotion)
fig = plt.figure()
ax = fig.add_subplot(111)
rects = ax.bar(range(10), 20*np.random.rand(10))
drs = []
for rect in rects:
dr = DraggableRectangle(rect)
dr.connect()
drs.append(dr)
plt.show()
웹 기반 버전은 궁극적으로 자바 스크립트로 작성됩니다. 파이썬에 대한 GUI 라이브러리는 Qt 바인딩 라이브러리 또는 tkinter를 추천합니다. 너는 내가 너에게 무엇을 시도했는지 또는 너가 붙잡고있는 것을 우리에게 보여주지 않았기 때문에 그 너머에 다른 것을 많이 가지고 있지 않다. – Aaron
나는 python-gantt와 matplotlib를 보았다. 문제는 matplotlib (또는 다른 도구)에 동일한 선을 그리는 방법, 즉 가로 막대의 시작 및 끝 위치를 지정하는 방법을 모르겠다는 것입니다. 그리고 같은 줄에 여러 번. 여기에 나는 붙어있다. 내가 보았고 시험했던 모든 예가 서로 아래에 막대를 그렸거나 쌓인 막대를 그렸기 때문에 막대 사이에 일정한 거리가 있어야하기 때문에 분명히 잘못되었습니다. – Gabor
책, 도구, 소프트웨어 라이브러리, 튜토리얼 또는 기타 오프 사이트 리소스 **를 추천하거나 찾도록 ** 요청하는 질문은 오타가있는 답변 및 스팸을 유치하는 경향이 있으므로 스택 오버플로 관련 주제와 관련이 없습니다. 대신, [문제 설명] (http://meta.stackoverflow.com/questions/254393) 및 지금까지 해결 된 사항은 무엇입니까? – MattDMo