本文整理汇总了Python中matplotlib.patches.Rectangle.set_facecolor方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.set_facecolor方法的具体用法?Python Rectangle.set_facecolor怎么用?Python Rectangle.set_facecolor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.set_facecolor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_facecolor [as 别名]
def __init__(self, x, y, dx, dy, border_tol=0.1, resize=True, plotview=None, **opts):
shape = Rectangle((float(x),float(y)), float(dx), float(dy), **opts)
if 'linewidth' not in opts:
shape.set_linewidth(1.0)
if 'facecolor' not in opts:
shape.set_facecolor('r')
super(NXrectangle, self).__init__(shape, border_tol, resize, plotview)
self.shape.set_label('Rectangle')
self.rectangle = self.shape
示例2: create_artists
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_facecolor [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]
示例3: draw_rectangle
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_facecolor [as 别名]
def draw_rectangle(self, lower, upper, node):
r = Rectangle(lower, upper[0] - lower[0], upper[1]-lower[1],
edgecolor='k',
facecolor = (0,0,0))
self.ax.add_patch(r)
if node.is_leaf():
rx, ry = r.get_xy()
cx = rx + r.get_width()/2.0
cy = ry + r.get_height()/2.0
r.set_facecolor( node.get_colour())
self.ax.annotate(node.get_weight(), (cx, cy), color=(0,0,0), fontsize = 10, ha='center', va='center')
print node.name, rx, ry, cx, cy
示例4: boundingBox
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_facecolor [as 别名]
def boundingBox(self, data, ax, label, bBoundingBoxes, bLabels):
''' Draw bounding box around data.'''
data = np.array(data)
width = max(data[:,0]) - min(data[:,0])
height = max(data[:,1]) - min(data[:,1])
r = Rectangle((min(data[:,0]), min(data[:,1])), width, height)
if bBoundingBoxes:
ax.add_artist(r)
r.set_clip_box(ax.bbox)
r.set_alpha(0.1)
r.set_facecolor((0.5, 0.5, 0.5))
if bLabels:
ax.annotate(label, xy = (min(data[:,0]), max(data[:,1])), xytext = (0, 0),
textcoords = 'offset points', ha = 'right', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.5', fc = (0.5, 0.5, 0.5), alpha = 0.1))
示例5: reduce
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_facecolor [as 别名]
print >> sys.stderr, "Number of reflectance and image points should be equal."
small = reduce(min, depths, depths[0])
depths = map(lambda f: f - small, depths)
start = x[0]
x = map(lambda f: f - start, x)
fig = plt.figure()
g = fig.add_subplot(3, 1, 1)
g.plot(x, depths)
g.set_xlim(x[0], x[len(x)-1])
ref = fig.add_subplot(3, 1, 2 )
for i in xrange(len(reflectance)):
e = Rectangle(xy=(i,0), width=1, height=1, edgecolor='none')
r = min(reflectance[i], 1)
e.set_facecolor([r, r, r])
ref.add_artist(e)
ref.set_frame_on(False)
ref.get_xaxis().set_visible(False)
ref.get_yaxis().set_visible(False)
ref.set_xlim(0, len(reflectance))
ref.set_ylim(0, 1)
ref = fig.add_subplot(3, 1, 3 )
for i in xrange(len(image)):
e = Rectangle(xy=(i,0), width=1, height=1, edgecolor='none')
e.set_facecolor([image[i], image[i], image[i]])
ref.add_artist(e)
ref.set_frame_on(False)
示例6: bkgd
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_facecolor [as 别名]
def bkgd(self):
# Black background
main_bkgd=Rectangle((0,0),1,1)
main_bkgd.set_facecolor(self.bkgd_color)
self.ax.add_artist(main_bkgd)
示例7: crust_box
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_facecolor [as 别名]
def crust_box(self,ord):
# Dashed lines to show zoom
plot.plot([0.01,0.408],[0.31,0.5],color='white',
ls='--',lw=1.5,zorder=ord)
plot.plot([0.51,0.412],[0.31,0.5],color='white',
ls='--',lw=1.5,zorder=ord)
# Boxes to provide background
box_bkgd1=Rectangle((0.01,0.01),0.5,0.3,zorder=ord,
color='white',lw=1.5)
self.ax.add_artist(box_bkgd1)
box_bkgd2=Rectangle((0.41,0.01),0.1,0.3,zorder=ord,lw=0)
box_bkgd2.set_facecolor(self.core_color)
self.ax.add_artist(box_bkgd2)
box_bkgd3=Rectangle((0.01,0.01),0.2,0.3,zorder=ord,lw=0)
box_bkgd3.set_facecolor(self.crust_color)
self.ax.add_artist(box_bkgd3)
box_bkgd4=Rectangle((0.21,0.01),0.2,0.3,zorder=ord,lw=0)
box_bkgd4.set_facecolor(self.neutron_color)
self.ax.add_artist(box_bkgd4)
# Nuclei
for j in range(0,20):
shift=rand()*0.02
if j%2==0:
shift=shift+0.15/float(j+2)
for i in range(0,j+2):
y=0.3*float(i)/float(j+2)+0.01+shift
if y>0.30:
y=0.30
nuc1=Ellipse((0.02+float(j)*0.02,y),
0.01,0.01,zorder=ord+1,lw=0)
nuc1.set_facecolor(self.core_color)
self.ax.add_artist(nuc1)
# Pasta
for i in range(0,60):
y=0.3*float(i)/60.0
if (y<0.03):
y=0.03
pasta1=Ellipse((0.40-0.1*rand()*rand(),y),
0.01,0.04,angle=rand()*360,zorder=ord+1,lw=0)
pasta1.set_facecolor(self.core_color)
self.ax.add_artist(pasta1)
# Thinner pasta
for i in range(0,20):
y=0.3*float(i)/20.0
if (y<0.04):
y=0.04
pasta2=Ellipse((0.415-0.04*rand()*rand(),y),
0.01,0.06,angle=rand()*60-30,zorder=ord+1,lw=0)
pasta2.set_facecolor(self.core_color)
self.ax.add_artist(pasta2)
# Labels
self.ax.text(0.05,0.12,'Outer',fontsize=self.font_scale*0.8,
color='black',
rotation='90',va='center',ha='center',zorder=ord+2,
bbox=dict(facecolor=self.crust_color,lw=0))
self.ax.text(0.09,0.12,'Crust',fontsize=self.font_scale*0.8,
color='black',
rotation='90',va='center',ha='center',zorder=ord+2,
bbox=dict(facecolor=self.crust_color,lw=0))
self.ax.text(0.21,0.12,'neutron drip',fontsize=self.font_scale*0.6,color='black',
rotation='90',va='center',ha='center',zorder=ord+2,
bbox=dict(facecolor=self.crust_color,lw=0))
self.ax.text(0.25,0.12,'Inner',fontsize=self.font_scale*0.8,
color='black',
rotation='90',va='center',ha='center',zorder=ord+2,
bbox=dict(facecolor=self.neutron_color,lw=0))
self.ax.text(0.29,0.12,'Crust',fontsize=self.font_scale*0.8,
color='black',
rotation='90',va='center',ha='center',zorder=ord+2,
bbox=dict(facecolor=self.neutron_color,lw=0))
self.ax.text(0.38,0.12,'Pasta',fontsize=self.font_scale*0.8,
color='black',
rotation='90',va='center',ha='center',zorder=ord+2,
bbox=dict(facecolor=self.core_color,lw=0))
self.ax.text(0.45,0.12,'Core',fontsize=self.font_scale*0.8,
color='black',
rotation='90',va='center',ha='center',zorder=ord+2)
# Density labels
self.ax.text(0.08,0.24,'g/cm$^{3}$:',fontsize=self.font_scale*0.8,
color='black',
va='bottom',ha='center',zorder=ord+2,
bbox=dict(facecolor=self.crust_color,lw=0))
self.ax.text(0.18,0.25,'$10^{11}$',fontsize=self.font_scale*0.8,
color='black',
va='bottom',ha='center',zorder=ord+2,
bbox=dict(facecolor=self.crust_color,lw=0))
self.ax.text(0.39,0.25,'$10^{14}$',fontsize=self.font_scale*0.8,
color='black',
va='bottom',ha='center',zorder=ord+2,
bbox=dict(facecolor=self.core_color,lw=0))
# Crust thickness label
self.ax.text(0.26,0.335,
'$R_{\mathrm{crust}}=0.4-2.0~\mathrm{km}$',
fontsize=self.font_scale*0.8,color=self.text_color,
va='center',ha='center',zorder=13,
bbox=dict(facecolor=self.bkgd_color,lw=0))
示例8: Zoom
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_facecolor [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))