本文整理汇总了Python中matplotlib.patches.Rectangle.set_linestyle方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.set_linestyle方法的具体用法?Python Rectangle.set_linestyle怎么用?Python Rectangle.set_linestyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.set_linestyle方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_gate_patch
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
def get_gate_patch(self):
'''Returns a matplotlib patch to be drawn on the canvas whose dimensions
have been computed from the current gate.
'''
x_min, x_max = self.subplot.get_xlim()
x_range = x_max - x_min
y_min, y_max = self.subplot.get_ylim()
y_range = y_max - y_min
for subgate in self.gate.get_subgates():
col = subgate.get_column()
if col == self.x_column:
x_min = subgate.get_min()
x_range = subgate.get_max() - subgate.get_min()
if col == self.y_column:
y_min = subgate.get_min()
y_range = subgate.get_max() - subgate.get_min()
if self.patch not in self.subplot.patches:
rect = Rectangle((x_min, y_min), x_range, y_range, animated=True)
rect.set_fill(False)
rect.set_linestyle('dashed')
self.patch = self.subplot.add_patch(rect)
else:
self.patch.set_bounds(x_min, y_min, x_range, y_range)
return self.patch
示例2: drawRect
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
def drawRect(particle, color="#ffffff", size = (64,128), centered=True):
if centered:
r = Rectangle((particle[0]-size[0]/2, particle[1]-size[1]/2), size[0], size[1], facecolor="none", edgecolor=color)
else:
r = Rectangle((particle[0], particle[1]), size[0], size[1], facecolor="none", edgecolor=color)
r.set_linestyle("dashed")
r.set_linewidth(3)
plt.gca().add_patch(r)
示例3: Annotate
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
class Annotate(object):
def __init__(self):
self.ax = plt.gca()
#self.ax = ax
#self.fig = fig
self.rect = Rectangle((0,0), 1, 1, facecolor='None', edgecolor='green')
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.is_pressed = False
self.ax.add_patch(self.rect)
#self.fig.canvas.mpl_connect('button_press_event',self.on_press)
#self.fig.canvas.mpl_connect('button_release_event', self.on_release)
#self.fig.canvas.mpl_connect('motion_notify_event', self.on_motion)
self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
self.ax.figure.canvas.draw()
def on_press(self, event):
print 'press'
self.is_pressed = True
self.x0 = event.xdata
self.y0 = event.ydata
print self.x0, self.y0
#self.rect.set_width(self.x1 - self.x0)
#self.rect.set_height(self.y1 - self.y0)
#self.rect.set_xy((self.x0, self.y0))
#self.rect.set_linestyle('dashed')
#self.fig.canvas.draw()
#self.ax.figure.canvas.draw()
def on_motion(self,event):
print 'motion'
if self.is_pressed is True:
return
self.x1 = event.xdata
self.y1 = event.ydata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('dashed')
#self.fig.canvas.draw()
self.ax.figure.canvas.draw()
def on_release(self, event):
print 'release'
self.is_pressed = False
self.x1 = event.xdata
self.y1 = event.ydata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('solid')
#self.fig.canvas.draw()
self.ax.figure.canvas.draw()
#time.sleep(3)
#plt.close()
print self.x0,self.y0,self.x1,self.y1
示例4: RoiRect
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
class RoiRect(object):
''' Class for getting a mouse drawn rectangle
Based on the example from:
http://matplotlib.org/users/event_handling.html#draggable-rectangle-exercise
Note that:
* It makes only one roi
'''
def __init__(self):
self.ax = plt.gca()
self.rect = Rectangle((0,0), 1, 1,fc='none', ec='r')
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.ax.add_patch(self.rect)
self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
def on_press(self, event):
print 'press'
self.x0 = event.xdata
self.y0 = event.ydata
self.rect.set_linestyle('dashed')
self.set = False
def on_release(self, event):
print 'release'
self.x1 = event.xdata
self.y1 = event.ydata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('solid')
self.ax.figure.canvas.draw()
self.set = True
self.ax.figure.canvas.mpl_disconnect(self.on_press)
self.ax.figure.canvas.mpl_disconnect(self.on_release)
self.ax.figure.canvas.mpl_disconnect(self.on_motion)
def on_motion(self, event):
# on motion will move the rect if the mouse
if self.x0 is None: return
if self.set: return
# if event.inaxes != self.rect.axes: return
self.x1 = event.xdata
self.y1 = event.ydata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.ax.figure.canvas.draw()
示例5: Annotate
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
class Annotate(object):
def __init__(self,ax=None):
if ax==None:
self.ax = plt.gca()
else:
self.ax = ax
self.rect = Rectangle((0,0), 0, 0, facecolor='yellow', edgecolor='yellow', alpha=.5, \
zorder=10, clip_on=False)
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.is_pressed = False
self.ax.add_patch(self.rect)
self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
def on_press(self, event):
self.is_pressed = True
print 'press'
self.x0 = event.xdata
self.y0 = event.ydata
self.x1 = event.xdata
self.y1 = event.ydata
if not np.any( [c==None for c in [self.x0,self.y0,self.x1,self.y1]] ):
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('dashed')
self.ax.figure.canvas.draw()
def on_motion(self,event):
if self.is_pressed is True:
self.x1 = event.xdata
self.y1 = event.ydata
if not np.any( [c==None for c in [self.x0,self.y0,self.x1,self.y1]] ):
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('dashed')
self.ax.figure.canvas.draw()
def on_release(self, event):
self.is_pressed = False
print 'release'
self.x1 = event.xdata
self.y1 = event.ydata
if not np.any( [c==None for c in [self.x0,self.y0,self.x1,self.y1]] ):
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('solid')
self.ax.figure.canvas.draw()
print self.x0,self.y0,self.x1,self.y1
if self.x0==self.x1 and self.y0==self.y1:
print type(self.__bases__)
示例6: RectangleSelectImagePanel
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
class RectangleSelectImagePanel(wx.Panel):
''' Panel that contains an image that allows the users to select an area of the image with the mouse. The user clicks and
holds the mouse to create a dotted rectangle, and when the mouse is released the rectangles origin, width and height can be
read. The dimensions of these readings are always relative to the original image, so even if the image is scaled up larger
to fit the panel the measurements will always refer to the original image.'''
def __init__(self, parent, pathToImage=None):
''' Initialise the panel. Setting an initial image is optional.'''
# Initialise the parent
wx.Panel.__init__(self, parent)
# Intitialise the matplotlib figure
self.figure = plt.figure()
# Create an axes, turn off the labels and add them to the figure
self.axes = plt.Axes(self.figure,[0,0,1,1])
self.axes.set_axis_off()
self.figure.add_axes(self.axes)
# Add the figure to the wxFigureCanvas
self.canvas = FigureCanvas(self, -1, self.figure)
# Initialise the rectangle
self.rect = Rectangle((0,0), 1, 1, facecolor='None', edgecolor='green')
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.axes.add_patch(self.rect)
# Sizer to contain the canvas
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 3, wx.ALL)
self.SetSizer(self.sizer)
self.Fit()
# Connect the mouse events to their relevant callbacks
self.canvas.mpl_connect('button_press_event', self._onPress)
self.canvas.mpl_connect('button_release_event', self._onRelease)
self.canvas.mpl_connect('motion_notify_event', self._onMotion)
# Lock to stop the motion event from behaving badly when the mouse isn't pressed
self.pressed = False
# If there is an initial image, display it on the figure
if pathToImage is not None:
self.setImage(pathToImage)
def _onPress(self, event):
''' Callback to handle the mouse being clicked and held over the canvas'''
# Check the mouse press was actually on the canvas
if event.xdata is not None and event.ydata is not None:
# Upon initial press of the mouse record the origin and record the mouse as pressed
self.pressed = True
self.rect.set_linestyle('dashed')
self.x0 = event.xdata
self.y0 = event.ydata
def _onRelease(self, event):
'''Callback to handle the mouse being released over the canvas'''
# Check that the mouse was actually pressed on the canvas to begin with and this isn't a rouge mouse
# release event that started somewhere else
if self.pressed:
# Upon release draw the rectangle as a solid rectangle
self.pressed = False
self.rect.set_linestyle('solid')
# Check the mouse was released on the canvas, and if it wasn't then just leave the width and
# height as the last values set by the motion event
if event.xdata is not None and event.ydata is not None:
self.x1 = event.xdata
self.y1 = event.ydata
# Set the width and height and origin of the bounding rectangle
self.boundingRectWidth = self.x1 - self.x0
self.boundingRectHeight = self.y1 - self.y0
self.bouningRectOrigin = (self.x0, self.y0)
# Draw the bounding rectangle
self.rect.set_width(self.boundingRectWidth)
self.rect.set_height(self.boundingRectHeight)
self.rect.set_xy((self.x0, self.y0))
self.canvas.draw()
def _onMotion(self, event):
'''Callback to handle the motion event created by the mouse moving over the canvas'''
# If the mouse has been pressed draw an updated rectangle when the mouse is moved so
# the user can see what the current selection is
if self.pressed:
# Check the mouse was released on the canvas, and if it wasn't then just leave the width and
#.........这里部分代码省略.........
示例7: ImagePanel
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
#.........这里部分代码省略.........
for v in set:
text, image, relief, command, side = v.split('$')
self.imgToolbar.append(tk.PhotoImage(file=image+'.gif'))
button = tk.Button(toolbar_frame, image=self.imgToolbar[-1], text=text, relief=eval(relief), command=eval(command))
button.pack(side=tk.LEFT, fill=tk.BOTH, expand=0)
return toolbar_frame
def drawRectangle(self):
print('Draw rectangle!')
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.xp0 = None
self.yp0 = None
self.xp1 = None
self.yp1 = None
self.rectangle = Rectangle((0,0), 1, 1, facecolor='None', edgecolor='green')
self.subplot.add_patch(self.rectangle)
self.ispressed = False
self.bpe = self.canvas.mpl_connect('button_press_event', self.drawRectangle_onPress)
self.bre = self.canvas.mpl_connect('button_release_event', self.drawRectangle_onRelease)
self.mne = self.canvas.mpl_connect('motion_notify_event', self.drawRectangle_onMotion)
def drawRectangle_onPress(self, event):
self.xp0 = event.x
self.yp0 = event.y
self.x0 = event.xdata
self.y0 = event.ydata
self.x1 = event.xdata
self.y1 = event.ydata
self.rectangle.set_width(self.x1-self.x0)
self.rectangle.set_xy((self.x0, self.y0))
self.rectangle.set_linestyle('dashed')
self.canvas.draw()
self.ispressed = True
def drawRectangle_onRelease(self, event):
self.xp1 = event.x
self.yp1 = event.y
self.x1 = event.xdata
self.y1 = event.ydata
self.rectangle.set_width(self.x1-self.x0)
self.rectangle.set_height(self.y1-self.y0)
self.rectangle.set_xy((self.x0, self.y0))
self.rectangle.set_linestyle('solid')
self.canvas.draw()
self.ispressed = False
self.canvas.mpl_disconnect(self.bpe)
self.canvas.mpl_disconnect(self.bre)
self.canvas.mpl_disconnect(self.mne)
print(self.xp0, self.yp0, self.xp1, self.yp1)
self.inform('<DrawRectangle>')
return (self.xp0, self.yp0, self.xp1, self.yp1)
def getRectanglePoints(self):
return (self.xp0, self.yp0, self.xp1, self.yp1)
def drawRectangle_onMotion(self, event):
if self.ispressed is True:
self.x1 = event.xdata
self.y1 = event.ydata
self.rectangle.set_width(self.x1-self.x0)
self.rectangle.set_height(self.y1-self.y0)
self.rectangle.set_xy((self.x0, self.y0))
示例8: MyMplCanvas
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
class MyMplCanvas(FigureCanvas):
"""Simple canvas with a sine plot."""
def __init__(self, parent=None, width=5, height=4, dpi=100):
self.fig = Figure(figsize=(width, height), dpi=dpi)
matplotlib.rcParams.update( {'font size': 9} )
self.axes = self.fig.add_subplot(111)
i = self.axes.imshow(np.outer( np.linspace(0,1,10),np.linspace(0,1,10) ), zorder=1 )
self.cbar = self.fig.colorbar(i)
# push cbar to right edge of canvas
cbaraxis = self.fig.axes[1]
cbaraxis.set_position( [.9,.1,.05,.8] )
# now size up the main plot a bit
self.axes.set_position( [.05, .1, .8, .8] )
# self.figure.canvas.draw()
# We want the axes cleared every time plot() is called
# self.axes.hold(False)
#
FigureCanvas.__init__(self, self.fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self,
QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
self.crosshairs_x = 0
self.crosshairs_y = 0
self.hline = self.axes.axhline(0, color='w', ls=':', zorder=9)
self.vline = self.axes.axvline(0, color='w', ls=':', zorder=9)
self.bg_rect = Rectangle((0,0), 0, 0, facecolor='blue', edgecolor='blue', alpha=.3, zorder=8 )
self.axes.add_patch(self.bg_rect)
# self.signal_rect = Rectangle((0,0), 0, 0, facecolor='red', edgecolor='red', alpha=.3, zorder=9 )
# self.axes.add_patch(self.signal_rect)
self.M_ex_rects = []
self.M_em_rects = []
self.phase_ex_rects = []
self.phase_em_rects = []
self.spot_rects = []
# self.anno = spot_picker.Annotate(self.axes)
self.rect = Rectangle((0,0), 0, 0, facecolor='yellow', edgecolor='yellow', alpha=.5, \
zorder=10, clip_on=False)
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.is_pressed = False
self.axes.add_patch(self.rect)
self.axes.figure.canvas.mpl_connect('button_press_event', self.on_press)
self.axes.figure.canvas.mpl_connect('button_release_event', self.on_release)
self.axes.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
self.axes.figure.canvas.mpl_connect('key_press_event', self.on_key)
self.draw()
def on_key(self, event):
print event
print event.key
# if self.crosshairs_active:
# if event.key=='up':
# self.
def on_press(self, event):
self.is_pressed = True
print 'press'
self.x0 = event.xdata
self.y0 = event.ydata
self.x1 = event.xdata
self.y1 = event.ydata
if not np.any( [c==None for c in [self.x0,self.y0,self.x1,self.y1]] ):
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('dashed')
self.figure.canvas.restore_region(self.blitbackground)
self.axes.draw_artist(self.rect)
self.figure.canvas.blit(self.axes.bbox)
# self.axes.figure.canvas.draw()
def on_motion(self,event):
if self.is_pressed is True:
self.x1 = event.xdata
self.y1 = event.ydata
if not np.any( [c==None for c in [self.x0,self.y0,self.x1,self.y1]] ):
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('dashed')
self.figure.canvas.restore_region(self.blitbackground)
self.axes.draw_artist(self.rect)
self.figure.canvas.blit(self.axes.bbox)
# self.axes.figure.canvas.draw()
def on_release(self, event):
self.is_pressed = False
#.........这里部分代码省略.........
示例9: InteractiveContinuumFit
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
class InteractiveContinuumFit(object):
def __init__(self, spec1d_object):
self.spec1d_object=spec1d_object
self.xdata=spec1d_object.vel_arr
self.ydata=spec1d_object.flux_arr
self.mask=np.array([1]*len(self.xdata))
self.rms_error=0
self.degree_of_fit=3
width_inches=12
height_inches=9
dpi=100
self.window=Tk.Tk()
self.window.wm_title('Fit Continuum')
self.window.geometry('%dx%d+%d+%d' % (width_inches*dpi, height_inches*dpi, 0, 0))
self.fig=plt.figure(1,figsize=(width_inches,height_inches),dpi=dpi)
self.ax=plt.subplot(111)
plt.subplots_adjust(bottom=0.2)
self.canvas=FigureCanvasTkAgg(self.fig,master=self.window)
self.canvas.show()
self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
finish_button = Tk.Button(master=self.window, text='Finish', command=self.finished_clicked,width=10)
finish_button['font']=tkFont.Font(family='Helvetica', size=18)
finish_button.place(relx=0.8,rely=0.95)
output_txt_button = Tk.Button(master=self.window, text='Output .txt', command=self.output_txt_clicked,width=10)
output_txt_button['font']=tkFont.Font(family='Helvetica', size=18)
output_txt_button.place(relx=0.8,rely=0.85)
output_fits_button = Tk.Button(master=self.window, text='Output .fits', command=self.output_fits_clicked,width=10)
output_fits_button['font']=tkFont.Font(family='Helvetica', size=18)
output_fits_button.place(relx=0.8,rely=0.90)
self.fit_increment_ax=plt.axes([0.1,0.12,0.03,0.03])
self.fit_decrement_ax=plt.axes([0.1,0.065,0.03,0.03])
self.degree_of_fit_text=Tk.StringVar()
self.degree_of_fit_text.set(str(self.degree_of_fit))
self.degree_readout_box=Tk.Entry(master=self.window, textvariable=self.degree_of_fit_text, width=3)
self.degree_readout_box.place(relx=0.1,rely=0.875)
self.rms_readout_ax=plt.figtext(0.14,0.03, str(self.rms_error), horizontalalignment='left')
plt.figtext(0.14,0.1,'Degree of Fit')
plt.figtext(0.13,0.03,'RMS Error:', horizontalalignment='right')
self.axes=[self.ax,self.fit_increment_ax,self.fit_decrement_ax]
plt.subplots_adjust(bottom=0.2)
self.rect = Rectangle((0,0), 0, 0, facecolor='red', edgecolor='red', alpha=0.2)
self.previous_rects=[]
self.previous_rects_x=[]
self.is_pressed=False
self.is_drawing_new_rect=False
self.x0 = None
self.y0 = self.ax.get_ylim()[0]
self.x1 = None
self.y1 = self.ax.get_ylim()[1]
self.lines=[]
self.ax.add_patch(self.rect)
self.window.protocol("WM_DELETE_WINDOW", self.finished_clicked)
self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
self.degree_of_fit_text.trace('w', self.dof_changed)
self.inc_fit_button=Button(self.fit_increment_ax, '/\\')
self.dec_fit_button=Button(self.fit_decrement_ax, '\\/')
self.UpdatePlots()
Tk.mainloop()
def on_press(self, event):
if event.inaxes == self.ax:
for x_marker in self.previous_rects_x:
x_min,y_min=x_marker.xy
x_max=x_min+x_marker.get_width()
y_max=y_min+x_marker.get_height()
if event.xdata > x_min and event.xdata <x_max and event.ydata>y_min and event.ydata<y_max:
for i in [np.where(self.xdata==x)[0][0] for x in self.xdata if (x>x_min and x<x_max)]:
self.mask[i]=1
del self.previous_rects[self.previous_rects_x.index(x_marker)]
del self.previous_rects_x[self.previous_rects_x.index(x_marker)]
return
if event.ydata==None:
return
self.rect = Rectangle((0,0), 0, 0, facecolor='red', edgecolor='red', alpha=0.2)
self.ax.add_patch(self.rect)
self.is_pressed=True
self.is_drawing_new_rect=True
self.x0 = event.xdata
self.x1 = event.xdata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('dashed')
self.ax.figure.canvas.draw()
elif event.inaxes == self.fit_increment_ax:
self.inc_clicked()
#.........这里部分代码省略.........
示例10: Annotate1
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
class Annotate1(FigureCanvas):
def __init__(self):
self.plot = Figure()
self.ax= self.plot.add_subplot(111)
img = Image.open(os.path.join(wrkdrr,'pic_resize.jpg'))
img = np.asarray(img)
print img
self.ax.imshow(img)
FigureCanvas.__init__(self, self.plot)
self.mpl_connect('button_press_event', self.on_press)
self.mpl_connect('button_release_event', self.on_release)
self.mpl_connect('button_draw', self.draw_callback)
self.rect = Rectangle((0,0), 1, 1, facecolor='None', edgecolor='green')
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.ax.add_patch(self.rect)
print "plot"
def draw_callback(self, event):
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
self.ax.draw_artist(self.poly)
self.ax.draw_artist(self.line)
self.canvas.blit(self.ax.bbox)
self.ax.figure.canvas.draw()
def on_press(self, event):
print 'press'
self.x0 = event.xdata
self.y0 = event.ydata
self.x1 = event.xdata
self.y1 = event.ydata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.ax.figure.canvas.draw()
def on_release(self, event):
print 'release'
self.x1 = event.xdata
self.y1 = event.ydata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('solid')
self.ax.figure.canvas.draw()
print self.x0,self.y0,self.x1,self.y1
global mask
mask = [self.y0,self.y1,self.x0,self.x1]
print mask
array = np.asarray(mask)
print array
with open(os.path.join(wrkdrr,'curr_proj.txt')) as f:
mask1 = f.readlines()[0]
np.savetxt(os.path.join(mask1,'mask.txt'), array, delimiter=' , ')
示例11: InteractiveContinuumFit
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
#.........这里部分代码省略.........
self.dec_fit_button['font']=tkFont.Font(family='Helvetica',size=18)
self.dec_fit_button.place(relx=0.12,y=self.degree_readout_box.winfo_y()+int(self.degree_readout_box.winfo_height()),anchor='n')
self.window.bind('<Configure>', self.configure)
self.UpdatePlots()
Tk.mainloop()
def configure(self,event):
self.inc_fit_button.place(relx=0.12,y=self.degree_readout_box.winfo_y(),anchor='s')
self.dec_fit_button.place(relx=0.12,y=self.degree_readout_box.winfo_y()+int(self.degree_readout_box.winfo_height()),anchor='n')
def on_press(self, event):
if event.inaxes == self.ax:
for x_marker in self.previous_rects_x:
x_min,y_min=x_marker.xy
x_max=x_min+x_marker.get_width()
y_max=y_min+x_marker.get_height()
if event.xdata > x_min and event.xdata <x_max and event.ydata>y_min and event.ydata<y_max:
for i in [np.where(self.xdata==x)[0][0] for x in self.xdata if (x>x_min and x<x_max)]:
self.mask[i]=1
del self.previous_rects[self.previous_rects_x.index(x_marker)]
del self.previous_rects_x[self.previous_rects_x.index(x_marker)]
return
if event.ydata==None:
return
self.rect = Rectangle((0,0), 0, 0, facecolor='red', edgecolor='red', alpha=0.2)
self.ax.add_patch(self.rect)
self.is_pressed=True
self.is_drawing_new_rect=True
self.x0 = event.xdata
self.x1 = event.xdata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('dashed')
self.ax.figure.canvas.draw()
#elif event.inaxes == self.fit_increment_ax:
# self.inc_clicked()
#elif event.inaxes == self.fit_decrement_ax:
# self.dec_clicked()
def on_motion(self,event):
#Updating slow due to canvas.draw(), speed up?
if self.is_pressed==False:
return
self.x1 = event.xdata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('dashed')
self.ax.figure.canvas.draw()
def on_release(self, event):
if event.ydata==None:
return
self.is_pressed=False
if self.is_drawing_new_rect==True:
self.x1 = event.xdata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.rect.set_linestyle('solid')
self.previous_rects.append(copy(self.rect))
x_marker=Rectangle((self.x0,0.95*self.y1),max([(self.x1-self.x0),0.01*(self.xdata[-1]-self.xdata[0])]),0.05*self.y1, facecolor='k',alpha=1)
self.previous_rects_x.append(x_marker)
for i in [np.where(self.xdata==x)[0][0] for x in self.xdata if (x>self.x0 and x<self.x1)]:
示例12: Zoom
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
class Zoom(object):
def __init__(self):
self.is_pressed = False
self.x0 = 0.0
self.y0 = 0.0
self.x1 = 0.0
self.y1 = 0.0
def zoom_init(self, x, y):
graph = Figure(figsize=(5,4), dpi=100)
self.ax = graph.add_subplot(111)
self.rect = Rectangle((0,0),0,0)
self.ax.add_patch(self.rect)
self.ax.plot(x, y)
canvas = FigureCanvasTkAgg(graph, master=RightFrame)
canvas.show()
print(x)
print(y)
canvas.get_tk_widget().grid(column=2, row=1, rowspan=2, sticky=(N, S, E, W))
self.aid = graph.canvas.mpl_connect('button_press_event', self.on_press)
self.bid = graph.canvas.mpl_connect('button_release_event', self.on_release)
self.cid = graph.canvas.mpl_connect('motion_notify_event', self.on_motion)
def on_press(self, event):
self.is_pressed = True
if event.xdata is not None and event.ydata is not None:
self.x0, self.y0 = event.xdata, event.ydata
self.rect.set_width(0)
self.rect.set_height(0)
self.rect.set_xy((self.x0, self.y0))
self.ax.figure.canvas.draw()
self.rect.set_facecolor('red')
self.rect.set_linestyle('dashed')
def on_motion(self, event):
if self.is_pressed:
if event.xdata is not None and event.ydata is not None:
self.x1, self.y1 = event.xdata, event.ydata
self.rect.set_width(self.x1 - self.x0)
self.rect.set_height(self.y1 - self.y0)
self.rect.set_xy((self.x0, self.y0))
self.ax.figure.canvas.draw()
def on_release(self, event):
self.is_pressed = False
RightFrame.config(cursor="arrow")
self.rect.set_facecolor('blue')
self.rect.set_linestyle('solid')
if self.x0 > self.x1:
if self.y0 > self.y1:
self.minX = self.x1
self.maxX = self.x0
self.minY = self.y1
self.maxY = self.y0
else:
self.minX = self.x1
self.maxX = self.x0
self.minY = self.y0
self.maxY = self.y1
if self.x0 < self.x1:
if self.y0 < self.y1:
self.minX = self.x0
self.maxX = self.x1
self.minY = self.y0
self.maxY = self.y1
else:
self.minX = self.x0
self.maxX = self.x1
self.minY = self.y1
self.maxY = self.y0
global minX, minY, maxX, maxY
minX = self.minX
minY = self.minY
maxX = self.maxX
maxY = self.maxY
graph = Figure(figsize=(5,4), dpi=100)
self.ax = graph.add_subplot(111)
self.ax.set_xlim(self.minX, self.maxX)
self.ax.set_ylim(self.minY, self.maxY)
self.ax.plot(x, y)
canvas = FigureCanvasTkAgg(graph, master=RightFrame)
canvas.show()
canvas.get_tk_widget().grid(column=2, row=1, rowspan=2, sticky=(N, S, E, W))
示例13: MyDialog
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linestyle [as 别名]
#.........这里部分代码省略.........
return
# The work button,start thread
def work(self,event):
t = MyThread(1,self)
t.start()
#t.join()
# CheckBox
def onCheck(self,event):
#wx.MessageBox(str(self.check.GetValue()),"Check?",wx.YES_NO|wx.ICON_QUESTION)
if self.check.GetValue():
self.frontBtn.Enable(False)
self.saveBtn.Enable(False)
self.nextBtn.Enable(False)
else:
self.frontBtn.Enable(True)
self.saveBtn.Enable(True)
self.nextBtn.Enable(True)
def _onPress(self, event):
''' Callback to handle the mouse being clicked and held over the canvas'''
# Check the mouse press was actually on the canvas
if event.xdata is not None and event.ydata is not None:
# Upon initial press of the mouse record the origin and record the mouse as pressed
self.pressed = True
self.rect.set_linestyle('dashed')
self.x0 = event.xdata
self.y0 = event.ydata
def _onRelease(self, event):
'''Callback to handle the mouse being released over the canvas'''
# Check that the mouse was actually pressed on the canvas to begin with and this isn't a rouge mouse
# release event that started somewhere else
if self.pressed:
# Upon release draw the rectangle as a solid rectangle
self.pressed = False
self.rect.set_linestyle('solid')
# Check the mouse was released on the canvas, and if it wasn't then just leave the width and
# height as the last values set by the motion event
if event.xdata is not None and event.ydata is not None:
self.x1 = event.xdata
self.y1 = event.ydata
# Set the width and height and origin of the bounding rectangle
self.boundingRectWidth = self.x1 - self.x0
self.boundingRectHeight = self.y1 - self.y0
self.bouningRectOrigin = (self.x0, self.y0)
# Draw the bounding rectangle
self.rect.set_width(self.boundingRectWidth)
self.rect.set_height(self.boundingRectHeight)
self.rect.set_xy((self.x0, self.y0))
self.canvas.draw()