本文整理汇总了Python中matplotlib.patches.Rectangle.set_transform方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.set_transform方法的具体用法?Python Rectangle.set_transform怎么用?Python Rectangle.set_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.set_transform方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_artists
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_transform [as 别名]
def create_artists(self, legend, orig_handle,
xdescent, ydescent, width, height, fontsize, trans):
p = Rectangle(xy=(-xdescent, -ydescent),
width=width, height=height)
self.update_prop(p, orig_handle, legend)
p.set_transform(trans)
return [p]
示例2: PlotPatchLine
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_transform [as 别名]
def PlotPatchLine(ax,prop):
length = ((prop['yEnd']-prop['yStart'])**2+(prop['zEnd']-prop['zStart'])**2) ** 0.5
ang = arctan((prop['zEnd']-prop['zStart'])/(prop['yEnd']-prop['yStart']))
ang = ang / 3.1415926*180
width = prop['widthLine']
patchi = Rectangle((prop['yStart'],prop['zStart']-width/2.0),length,width,color='blue',alpha=0.5)
t2 = matplotlib.transforms.Affine2D().rotate_deg(ang) + ax.transData
patchi.set_transform(t2)
ax.add_patch(patchi)
示例3: create_artists
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_transform [as 别名]
def create_artists(self, legend, orig_handle,
xdescent, ydescent, width, height, fontsize, trans):
p1 = Rectangle(xy=(-xdescent, -ydescent),
width=width, height=height)
p2 = Rectangle(xy=(-xdescent, -ydescent),
width=width, height=height)
self.update_prop(p1, orig_handle, legend)
self.update_prop(p2, orig_handle, legend)
p2.set_facecolor('none')
p1.set_transform(trans)
p2.set_transform(trans)
return [p1,p2]
示例4: showBitPositions
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_transform [as 别名]
def showBitPositions(self,ax,color=[0,0,255]):
color=[c/255. for c in color]
px,py,tx,ty=self.descriptor.getBits(self.cell)
truth=np.hstack((tx,ty))
for i,pos in enumerate(np.vstack((px,py))):
if truth[i]:
fc="r"
else:
fc="none"
xy=self.invTransForm([(pos[0]-0.5/self.scale),(pos[1]-0.5/self.scale)])
p = Rectangle(xy,width=self.descriptor.bitDistance/self.scale,height=-self.descriptor.bitDistance/self.scale,
fc=fc,lw=1,alpha=0.3)
t = MPLTransforms.Affine2D().rotate_around(xy[0],xy[1],-self.angle/180.*np.pi) + ax.transData
p.set_transform(t)
ax.add_artist(p)
示例5: showNanowires
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_transform [as 别名]
def showNanowires(self,ax,wires,color=[0,0,128],color_best=[128,0,0],alpha=0.5):
color=[c/255. for c in color]
color_best=[c/255. for c in color_best]
bestAspect=np.argmax([wire.Length for wire in wires])
for n,wire in enumerate(wires):
if n == bestAspect:
c=color_best
else:
c=color
p1 = Rectangle(wire.leftBottomCorner,width=wire.Width,height=wire.Length,color="none",fc=c,alpha=0.2)
p2 = Rectangle(wire.leftBottomCorner,width=wire.Width,height=wire.Length,color=c,fc="none",lw=1)
t = MPLTransforms.Affine2D().rotate_around(wire.Center[0],wire.Center[1],wire.Angle) + ax.transData
p1.set_transform(t)
p2.set_transform(t)
ax.add_artist(p1)
ax.add_artist(p2)
示例6: showMarkers
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_transform [as 别名]
def showMarkers(self,ax,color=[128,0,0],lw=1,ms=10,marker="+",cellFrame=False):
color=[c/255. for c in color]
for key in self.markers.keys():
if key != "others":
ax.add_artist(plt.Line2D([self.markers[key].Center[0]],
[self.markers[key].Center[1]],
color=color,marker=marker,ms=ms))
ax.add_artist(plt.Line2D([self.center[0]],
[self.center[1]],
color=color,marker=marker,ms=ms*2))
if cellFrame:
xy=self.invTransForm([-self.descriptor.markerArea[0]/2.,self.descriptor.markerArea[1]/2.])
t = MPLTransforms.Affine2D().rotate_around(xy[0],xy[1],-self.angle/180.*np.pi) + ax.transData
p = Rectangle(xy,width=self.descriptor.markerArea[0]/self.scale,height=self.descriptor.markerArea[1]/self.scale,
fc="none",lw=lw,color=color)
p.set_transform(t)
ax.add_artist(p)
示例7: animate
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_transform [as 别名]
def animate(i):
x,y = path[i]
#theta = path_dif(i)
path_dif = path[i+1] - path[i]
theta = atan2(path_dif[1], path_dif[0])
print(robot.get_width(), robot.get_height())
robot.set_xy((x - robot.get_width() / 2,y - robot.get_height() / 2))
robot_center = center_from_rectangle(robot)
rake.set_xy(robot_center - np.array([20, rake.get_height() / 2]))
front_wheel.set_xy(robot_center + np.array([5, - front_wheel.get_height()/2]))
trans = ax.transData
t = Affine2D().rotate_deg_around(robot_center[0],
robot_center[1], theta / pi * 180)
tt = t + trans
robot.set_transform(tt)
rake.set_transform(tt)
rake_rect = Rectangle(rake.get_xy(), rake.get_width(), rake.get_height())
front_wheel.set_transform(tt)
rake_rect.set_transform(t)
rake_trace.append(rake_rect)
rake_trace_patch_collection.set_paths(rake_trace)
示例8: updateImage
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_transform [as 别名]
def updateImage(self):
items=self.fileList.selectedItems()
if not items:
for i in range(len(self.imageAnnotations)):
self.imageAnnotations.pop(0).remove()
for i in range(len(self.canvas.axes.images)):
self.canvas.axes.images[i].remove()
try:
self.endSelector.disconnect()
except:
pass
self.endSelector = None
self.lastImage=None
self.canvas.draw()
return
index=self.fileList.indexOfTopLevelItem(items[0])
for i in range(len(self.imageAnnotations)):
self.imageAnnotations.pop(0).remove()
# self.canvas.axes.clear()
## TODO: get directly from axes, avoid the list
if index >= 0:
if self.lastImage!=self.project.paths[index]:
for i in range(len(self.canvas.axes.images)):
self.canvas.axes.images[i].remove()
# print imread(self.project.paths[index])
self.canvas.axes.imshow(imread(self.project.paths[index]),interpolation="None")
self.lastImage=self.project.paths[index]
# if items[0].checkState(0):
if self.project.settings[index]["cell"]==None:
self.canvas.draw()
return
for pos in self.project.settings[index]["markers"]:
p=plt.Line2D([pos[0]],[pos[1]],color=[1,0,0],marker="+",ms=5)
self.canvas.axes.add_artist(p)
self.imageAnnotations.append(p)
pos=self.project.settings[index]["center"]
p=plt.Line2D([pos[0]],[pos[1]],color=[1,0,0],marker="+",ms=10)
self.canvas.axes.add_artist(p)
self.imageAnnotations.append(p)
px,py,tx,ty=self.project.descriptor.getBits(self.project.settings[index]["cell"])
invTransForm=self.project.createInverseTransformFunc(index)
scale=self.project.settings[index]["scale"]
angle=self.project.settings[index]["angle"]
truth=np.hstack((tx,ty))
for i,pos in enumerate(np.vstack((px,py))):
if truth[i]:
fc="r"
else:
fc="none"
xy=invTransForm([(pos[0]-self.project.descriptor.markerSize*2.),(pos[1]-self.project.descriptor.markerSize*2.)])
p = Rectangle(xy,width=self.project.descriptor.bitDistance/scale,height=-self.project.descriptor.bitDistance/scale,
fc=fc,lw=1,alpha=0.3)
t = MPLTransforms.Affine2D().rotate_around(xy[0],xy[1],-angle/180.*np.pi) + self.canvas.axes.transData
p.set_transform(t)
self.canvas.axes.add_artist(p)
self.imageAnnotations.append(p)
if self.previewCheck.checkState():
a=self.project.showCell(self.canvas.axes,index)
self.imageAnnotations.extend(a)
if self.project.settings[index]["mode"]=="manual":
try:
self.endSelector.disconnect()
except:
pass
self.endSelector=endSelector(self,index) ## TODO improve: change properties, do not always override
else:
try:
self.endSelector.disconnect()
except:
pass
self.endSelector = None
# else: ## TODO: clean up this mess with disconnect
# try:
# self.endSelector.disconnect()
# except:
# pass
# self.endSelector = None
else:
for i in range(len(self.canvas.axes.images)):
self.canvas.axes.images[i].remove()
try:
self.endSelector.disconnect()
except:
pass
self.endSelector = None
self.lastImage=None
self.canvas.draw()
示例9: plot_RGB
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_transform [as 别名]
#.........这里部分代码省略.........
else:
fig = aplpy.FITSFigure(title+'_rgb_cube_2d.fits',figure=figname,subplot=subplot)
fig.show_rgb(title+'_rgb_cube.png')
# coordinates of the center of the image
c = SkyCoord(ra=ra,dec=dec,frame='fk5',unit=(u.hour,u.deg))
# recenter image
fig.recenter(c.ra.deg,c.dec.deg,radius=radius/3600.)
# put axes on top
fig.tick_labels.set_xposition('top')
fig.axis_labels.set_xposition('top')
fig.tick_labels.set_font(size='small')
fig.tick_labels.set_xformat('hh:mm:ss')
fig.tick_labels.set_yformat('dd:mm:ss')
#fig.ticks.set_xspacing(10./3600.)
# turn grid on
if show_grid:
fig.add_grid()
# show/hide axes
if not show_xaxis:
fig.axis_labels.hide_x()
fig.tick_labels.hide_x()
if not show_yaxis:
fig.axis_labels.hide_y()
fig.tick_labels.hide_y()
if show_labels:
c = SkyCoord(ra='20h07m06.782s',dec='27d28m43.00s',frame='fk5',unit=(u.hour,u.deg))
fig.add_label(c.ra.deg,c.dec.deg,'SOF1',color='red',weight='bold',size=20)
c = SkyCoord(ra='20h07m06.798s',dec='27d28m56.48s',frame='fk5',unit=(u.hour,u.deg))
fig.add_label(c.ra.deg,c.dec.deg,'SOF2',color='red',weight='bold',size=20)
c = SkyCoord(ra='20h07m06.458s',dec='27d29m00.78s',frame='fk5',unit=(u.hour,u.deg))
fig.add_label(c.ra.deg,c.dec.deg,'SOF3',color='red',weight='bold',size=20)
c = SkyCoord(ra='20h07m05.592s',dec='27d29m03.0s',frame='fk5',unit=(u.hour,u.deg))
fig.add_label(c.ra.deg,c.dec.deg,'SOF4',color='red',weight='bold',size=20)
c = SkyCoord(ra='20h07m05.795s',dec='27d28m46.82s',frame='fk5',unit=(u.hour,u.deg))
fig.add_label(c.ra.deg,c.dec.deg,'SOF5',color='red',weight='bold',size=20)
# add title
fig.add_label(0.2,0.9,title,relative=True,color='red',weight='bold')
#fig.set_title(title)
# load source list
sources = pickle.load(open(folder_export+"totsourcetable_fits.data","r"))
# extract only the RA, DEC column for name
if show_circles:
for i in range(len(sources)):
if name in sources['SOFIA_name'][i] and "Total_Cluster" not in sources['Property'][i]:
s = "%d" % (i)
fig.show_circles(sources['RA'][i],sources['DEC'][i],radius_source/3600.,edgecolor='red',facecolor='none',alpha=0.8,lw=2,label=s)
# add scalebar
if show_scalebar:
scale_pc = 1./dist*scale_bar
fig.add_scalebar(scale_bar/3600.)
#fig.scalebar.set_frame(True)
fig.scalebar.set_alpha(0.7)
fig.scalebar.set_color('red')
fig.scalebar.set_label('%d" = %.3f pc' % (scale_bar,scale_pc))
fig.scalebar.set_linewidth(3)
fig.scalebar.set_font(weight='bold')
# add another dashed rectangle showing the region of interest
if show_focus:
rafoc,decfoc,sizefoc=focus
foc = SkyCoord(ra=rafoc,dec=decfoc,frame='fk5',unit=(u.hour,u.deg))
fig.show_rectangles(foc.ra.deg,foc.dec.deg,sizefoc/3600.,decfoc/3600.,edgecolor='red',facecolor='none',alpha=0.8,lw=2,linestyle='dashed')
# show the SOFIA fields
if show_fields:
patches = []
for field in fields:
raf,decf,ang,width = field
c = SkyCoord(ra=raf,dec=decf,frame='fk5',unit=(u.hour,u.deg))
xp, yp = wcs_util.world2pix(fig._wcs, c.ra, c.dec)
wp = hp = width/3600. / wcs_util.celestial_pixel_scale(fig._wcs)
rect = Rectangle((-wp/2., -hp/2), width=wp, height=hp)
t1 = mpl.transforms.Affine2D().rotate_deg(ang).translate(xp, yp)
rect.set_transform(t1)
patches.append(rect)
# add all patches to the collection
p = PatchCollection(patches, edgecolor='white',facecolor='none',alpha=0.8,lw=2)
# add collection to figure
t = fig._ax1.add_collection(p)
# display contours
if contours != None:
fig.show_contour(contours,colors='white',returnlevels=True,levels=contours_levels)
if show:
plt.show()
示例10: draw_rectange
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_transform [as 别名]
def draw_rectange(self, xy, r, w, h):
r = r*180/math.pi
rect = Rectangle((xy[0]-w/2.0, xy[1]-h/2.0), w, h, 0, fill=False)
trans = mpl.transforms.Affine2D().rotate_deg_around(xy[0], xy[1], r) + self.ax.transData
rect.set_transform(trans)
self.ax.add_patch(rect)