実際にOKです。これは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()
ウェブベースのバージョンが最終的にJavaScriptで記述されます。 Python用のGUIライブラリについては、Qtバインディングライブラリまたはtkinterをお勧めします。私があなたに何を試してみたのか、何をつかまえているのかを私たちに見せてくれなかったので、それ以上にあなたのために他にはありません – Aaron
私はpython-ganttとmatplotlibを見たことがあります。問題はmatplotlib(または他のツール)に同じ行を描画する、つまり水平バーの開始位置と終了位置を与える方法を知らないことです。そして、これは同じ行のために何度も。ここで私は立ち往生している。私が見て試したすべての例は、バーを互いに下に引っ張ったり積み重なったバーを描いているので、明らかに間違っているのはバーの間に一定の距離がなければならないからです。 – Gabor
本、ツール、ソフトウェアライブラリ、チュートリアル、またはその他のオフサイトリソースを推薦**して見つける**の質問は、オピニオン回答とスパムを引き付ける傾向があるため、スタックオーバーフローに関するトピックではありません。代わりに、[問題を説明する](http://meta.stackoverflow.com/questions/254393)、これを解決するためにこれまでに何が行われているか。 – MattDMo