本文整理汇总了Python中matplotlib.figure.Figure.hitlist方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.hitlist方法的具体用法?Python Figure.hitlist怎么用?Python Figure.hitlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.hitlist方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImageSegmentAdjustWindow
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import hitlist [as 别名]
class ImageSegmentAdjustWindow(wx.Window, Knob):
def __init__(self, *args, **kwargs):
wx.Window.__init__(self, *args, **kwargs)
self.image_file = '.\\static\\images\\number_systems\\mayadays.gif'
self.lines = []
self.figure = Figure()
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.canvas.callbacks.connect('button_press_event', self.mouseDown)
self.canvas.callbacks.connect('motion_notify_event', self.mouseMotion)
self.canvas.callbacks.connect('button_release_event', self.mouseUp)
self.state = ''
self.mouseInfo = (None, None, None, None)
self.f0 = Param(2., minimum=0., maximum=6.)
self.A = Param(1., minimum=0.01, maximum=2.)
self.draw()
# Not sure I like having two params attached to the same Knob,
# but that is what we have here... it works but feels kludgy -
# although maybe it's not too bad since the knob changes both params
# at the same time (both f0 and A are affected during a drag)
self.f0.attach(self)
self.A.attach(self)
self.Bind(wx.EVT_SIZE, self.sizeHandler)
def sizeHandler(self, *args, **kwargs):
self.canvas.SetSize(self.GetSize())
def mouseDown(self, evt):
if self.lines[0] in self.figure.hitlist(evt):
self.state = 'frequency'
elif self.lines[1] in self.figure.hitlist(evt):
self.state = 'time'
else:
self.state = ''
self.mouseInfo = (evt.xdata, evt.ydata, max(self.f0.value, .1), self.A.value)
def mouseMotion(self, evt):
if self.state == '':
return
x, y = evt.xdata, evt.ydata
if x is None: # outside the axes
return
x0, y0, f0Init, AInit = self.mouseInfo
self.A.set(AInit+(AInit*(y-y0)/y0), self)
if self.state == 'frequency':
self.f0.set(f0Init+(f0Init*(x-x0)/x0))
elif self.state == 'time':
if (x-x0)/x0 != -1.:
self.f0.set(1./(1./f0Init+(1./f0Init*(x-x0)/x0)))
def mouseUp(self, evt):
self.state = ''
def draw(self):
if not hasattr(self, 'ax'):
self.axOriginal = self.figure.add_subplot(221)
self.axGreyScale = self.figure.add_subplot(222)
self.axFiltered = self.figure.add_subplot(223)
self.axSegments = self.figure.add_subplot(224)
self.image = data.coins()
# self.image = imread(self.image_file)
self.axOriginal.set_title("Original Image", fontsize=12)
self.axOriginal.imshow(self.image)
self.axGreyScale.set_title("Greyscale Image", fontsize=12)
self.grey_image = color.rgb2grey(self.image)
self.axGreyScale.imshow(self.grey_image, cmap = cm.Greys_r)
self.filter_image()
# thresh = threshold_otsu(self.grey_image)
# self.bw_image = closing(self.grey_image > thresh, square(1))
# self.axThreshold.imshow(self.bw_image)
self.axSegments.set_title("Segmented Image", fontsize=12)
self.label_image = label(self.filtered)
# borders = np.logical_xor(self.bw_image, self.cleared)
# self.label_image[borders] = -1
# fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
self.axSegments.imshow(self.label_image, cmap='jet')
for region in regionprops(self.label_image, ['Area', 'BoundingBox']):
# skip small images
if region['Area'] < 100:
continue
# draw rectangle around segmented coins
minr, minc, maxr, maxc = region['BoundingBox']
rect = mpatches.Rectangle((minc, minr), maxc - minc, maxr - minr, fill=False, edgecolor='red', linewidth=2)
self.axSegments.add_patch(rect)
# x1, y1, x2, y2 = self.compute(self.f0.value, self.A.value)
# color = (1., 0., 0.)
# self.lines += self.subplot1.plot(x1, y1, color=color, linewidth=2)
# self.lines += self.subplot2.plot(x2, y2, color=color, linewidth=2)
# #Set some plot attributes
# self.subplot1.set_title("Click and drag waveforms to change frequency and amplitude", fontsize=12)
#.........这里部分代码省略.........
示例2: FourierDemoWindow
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import hitlist [as 别名]
class FourierDemoWindow(wx.Window, Knob):
def __init__(self, *args, **kwargs):
wx.Window.__init__(self, *args, **kwargs)
self.lines = []
self.figure = Figure()
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.canvas.callbacks.connect('button_press_event', self.mouseDown)
self.canvas.callbacks.connect('motion_notify_event', self.mouseMotion)
self.canvas.callbacks.connect('button_release_event', self.mouseUp)
self.state = ''
self.mouseInfo = (None, None, None, None)
self.f0 = Param(2., minimum=0., maximum=6.)
self.A = Param(1., minimum=0.01, maximum=2.)
self.draw()
# Not sure I like having two params attached to the same Knob,
# but that is what we have here... it works but feels kludgy -
# although maybe it's not too bad since the knob changes both params
# at the same time (both f0 and A are affected during a drag)
self.f0.attach(self)
self.A.attach(self)
self.Bind(wx.EVT_SIZE, self.sizeHandler)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, event):
self.canvas.draw()
event.Skip()
def sizeHandler(self, *args, **kwargs):
self.canvas.SetSize(self.GetSize())
def mouseDown(self, evt):
if self.lines[0] in self.figure.hitlist(evt):
self.state = 'frequency'
elif self.lines[1] in self.figure.hitlist(evt):
self.state = 'time'
else:
self.state = ''
self.mouseInfo = (evt.xdata, evt.ydata,
max(self.f0.value, .1),
self.A.value)
def mouseMotion(self, evt):
if self.state == '':
return
x, y = evt.xdata, evt.ydata
if x is None: # outside the axes
return
x0, y0, f0Init, AInit = self.mouseInfo
self.A.set(AInit + (AInit * (y - y0) / y0), self)
if self.state == 'frequency':
self.f0.set(f0Init + (f0Init * (x - x0) / x0))
elif self.state == 'time':
if (x - x0) / x0 != -1.:
self.f0.set(1. / (1. / f0Init + (1. / f0Init * (x - x0) / x0)))
def mouseUp(self, evt):
self.state = ''
def draw(self):
if not hasattr(self, 'subplot1'):
self.subplot1 = self.figure.add_subplot(211)
self.subplot2 = self.figure.add_subplot(212)
x1, y1, x2, y2 = self.compute(self.f0.value, self.A.value)
color = (1., 0., 0.)
self.lines += self.subplot1.plot(x1, y1, color=color, linewidth=2)
self.lines += self.subplot2.plot(x2, y2, color=color, linewidth=2)
# Set some plot attributes
self.subplot1.set_title(
"Click and drag waveforms to change frequency and amplitude",
fontsize=12)
self.subplot1.set_ylabel("Frequency Domain Waveform X(f)", fontsize=8)
self.subplot1.set_xlabel("frequency f", fontsize=8)
self.subplot2.set_ylabel("Time Domain Waveform x(t)", fontsize=8)
self.subplot2.set_xlabel("time t", fontsize=8)
self.subplot1.set_xlim([-6, 6])
self.subplot1.set_ylim([0, 1])
self.subplot2.set_xlim([-2, 2])
self.subplot2.set_ylim([-2, 2])
self.subplot1.text(0.05, .95,
r'$X(f) = \mathcal{F}\{x(t)\}$',
verticalalignment='top',
transform=self.subplot1.transAxes)
self.subplot2.text(0.05, .95,
r'$x(t) = a \cdot \cos(2\pi f_0 t) e^{-\pi t^2}$',
verticalalignment='top',
transform=self.subplot2.transAxes)
def compute(self, f0, A):
f = np.arange(-6., 6., 0.02)
t = np.arange(-2., 2., 0.01)
x = A * np.cos(2 * np.pi * f0 * t) * np.exp(-np.pi * t ** 2)
X = A / 2 * \
(np.exp(-np.pi * (f - f0) ** 2) + np.exp(-np.pi * (f + f0) ** 2))
return f, X, t, x
def repaint(self):
self.canvas.draw()
#.........这里部分代码省略.........
示例3: FourierDemoWindow
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import hitlist [as 别名]
class FourierDemoWindow(wx.Window, Knob):
def __init__(self, *args, **kwargs):
wx.Window.__init__(self, *args, **kwargs)
self.lines = []
self.imgs = []
self.bkgrnd = []
self.mean = []
self.figure = Figure()
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.canvas.callbacks.connect('button_press_event', self.mouseDown)
self.canvas.callbacks.connect('motion_notify_event', self.mouseMotion)
self.canvas.callbacks.connect('button_release_event', self.mouseUp)
self.state = ''
self.mov=cb.load('movies/demoMovie.tif',fr=20)
with np.load('results_analysis.npz') as ld:
self.comps=np.transpose(np.reshape(ld['A2'],(ld['d1'],ld['d2'],-1),order='F'),[2,0,1])
self.mean = np.mean(self.mov,0)
self.mouseInfo = (None, None, None, None)
self.f0 = Param(np.percentile(self.mean,95), minimum=np.min(self.mean), maximum=np.max(self.mean))
self.A = Param(1, minimum=0, maximum=self.mov.shape[0],step=1)
self.toggle_background = BoolParam(True)
self.draw()
# Not sure I like having two params attached to the same Knob,
# but that is what we have here... it works but feels kludgy -
# although maybe it's not too bad since the knob changes both params
# at the same time (both f0 and A are affected during a drag)
self.f0.attach(self)
self.A.attach(self)
self.toggle_background.attach(self)
self.Bind(wx.EVT_SIZE, self.sizeHandler)
def sizeHandler(self, *args, **kwargs):
self.canvas.SetSize(self.GetSize())
def mouseDown(self, evt):
if self.lines[0] in self.figure.hitlist(evt):
self.state = 'frequency'
elif self.lines[1] in self.figure.hitlist(evt):
self.state = 'time'
else:
self.state = ''
self.mouseInfo = (evt.xdata, evt.ydata, max(self.f0.value, .1), self.A.value)
def mouseMotion(self, evt):
if self.state == '':
return
x, y = evt.xdata, evt.ydata
if x is None: # outside the axes
return
x0, y0, f0Init, AInit = self.mouseInfo
self.A.set(AInit+(AInit*(y-y0)/y0), self)
if self.state == 'frequency':
self.f0.set(f0Init+(f0Init*(x-x0)/x0))
elif self.state == 'time':
if (x-x0)/x0 != -1.:
self.f0.set(1./(1./f0Init+(1./f0Init*(x-x0)/x0)))
def mouseUp(self, evt):
self.state = ''
def draw(self):
if not hasattr(self, 'subplot1'):
self.subplot1 = self.figure.add_subplot(121)
self.subplot2 = self.figure.add_subplot(122)
x1, y1, x2, y2 = self.compute(self.f0.value, self.A.value)
color = (1., 0., 0.)
self.bkgrnd = self.subplot1.imshow(self.mean, cmap='gray',vmax=self.f0.value)
# self.lines += self.subplot2.plot(x2, y2, color=color, linewidth=2)
self.img = self.subplot2.imshow(self.mov[0], cmap='gray')
#Set some plot attributes
self.subplot1.set_title("Overlaid components", fontsize=12)
self.subplot2.set_title("Movie frames", fontsize=12)
# self.subplot1.set_ylabel("Frequency Domain Waveform X(f)", fontsize = 8)
# self.subplot1.set_xlabel("frequency f", fontsize = 8)
# self.subplot2.set_ylabel("Time Domain Waveform x(t)", fontsize = 8)
# self.subplot2.set_xlabel("time t", fontsize = 8)
# self.subplot1.set_xlim([-6, 6])
# self.subplot1.set_ylim([0, 1])
# self.subplot2.set_xlim([-2, 2])
# self.subplot2.set_ylim([-2, 2])
# self.subplot1.text(0.05, .95, r'$X(f) = \mathcal{F}\{x(t)\}$', \
# verticalalignment='top', transform = self.subplot1.transAxes)
# self.subplot2.text(0.05, .95, r'$x(t) = a \cdot \cos(2\pi f_0 t) e^{-\pi t^2}$', \
# verticalalignment='top', transform = self.subplot2.transAxes)
def compute(self, f0, A):
f = np.arange(-6., 6., 0.02)
t = np.arange(-2., 2., 0.01)
x = A*np.cos(2*np.pi*f0*t)*np.exp(-np.pi*t**2)
X = A/2*(np.exp(-np.pi*(f-f0)**2) + np.exp(-np.pi*(f+f0)**2))
return f, X, t, x
def repaint(self):
self.canvas.draw()
#.........这里部分代码省略.........