2016-10-19 4 views
-2

차트의 gantt 자원 유형을 그려야합니다. 전부 enter image description here동일한 줄에 가로 막대를 그립니다.

우리는 약 200 자원을 가지고 : 아이디어는 같은 줄에 여러 개의 수평 바 그릴 시작 날짜와 날짜

이있는 예상 된 결과로 표시되는 각각의 길이를 (자원에 해당)이다 최대 각 작업에 대해 50 개의 작업이 표시되므로 성능이 중요합니다.

아이디어가 있으십니까?

또한 작업은 마우스로 드래그 할 수 있어야합니다. 솔루션 (지방 GUI (PyQt는, wxwidget, Tkinter를, ...) 또는 웹 기반 플라스크, web2py 등) 나는 거 속임수 야하고 Matplotlib Documentation에서 바로 당신이 뭔가를 게시,

+0

웹 기반 버전은 궁극적으로 자바 스크립트로 작성됩니다. 파이썬에 대한 GUI 라이브러리는 Qt 바인딩 라이브러리 또는 tkinter를 추천합니다. 너는 내가 너에게 무엇을 시도했는지 또는 너가 붙잡고있는 것을 우리에게 보여주지 않았기 때문에 그 너머에 다른 것을 많이 가지고 있지 않다. – Aaron

+0

나는 python-gantt와 matplotlib를 보았다. 문제는 matplotlib (또는 다른 도구)에 동일한 선을 그리는 방법, 즉 가로 막대의 시작 및 끝 위치를 지정하는 방법을 모르겠다는 것입니다. 그리고 같은 줄에 여러 번. 여기에 나는 붙어있다. 내가 보았고 시험했던 모든 예가 서로 아래에 막대를 그렸거나 쌓인 막대를 그렸기 때문에 막대 사이에 일정한 거리가 있어야하기 때문에 분명히 잘못되었습니다. – Gabor

+0

책, 도구, 소프트웨어 라이브러리, 튜토리얼 또는 기타 오프 사이트 리소스 **를 추천하거나 찾도록 ** 요청하는 질문은 오타가있는 답변 및 스팸을 유치하는 경향이 있으므로 스택 오버플로 관련 주제와 관련이 없습니다. 대신, [문제 설명] (http://meta.stackoverflow.com/questions/254393) 및 지금까지 해결 된 사항은 무엇입니까? – MattDMo

답변

1

사실 확인이다. 이렇게하면 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() 
+0

이것은 같은 줄에 막대를 표시하지 않습니다. 하지만 Aaron I'v로부터 그 해결책을 얻었습니다. 큰! – Gabor

관련 문제