本文整理汇总了Python中matplotlib.patches.Rectangle.set_linewidth方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.set_linewidth方法的具体用法?Python Rectangle.set_linewidth怎么用?Python Rectangle.set_linewidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.set_linewidth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linewidth [as 别名]
def draw(self):
dpi = self.prefs['dpi']
ax_xsize = self.ax.get_window_extent().width
ax_ysize = self.ax.get_window_extent().height
nLabels = len(self.labels)
nColumns = min(self.prefs['legend_max_columns'],int(ax_xsize/self.column_width))
maxRows = self.prefs['legend_max_rows']
nRows_ax = int(ax_ysize/1.6/self.prefs['text_size'])
nRows_label = nLabels/nColumns + (nLabels%nColumns != 0)
nRows = max(1,min(min(nRows_label,maxRows),nRows_ax ))
maxLabels = nColumns*nRows - 1
self.ax.set_xlim(0.,float(ax_xsize))
self.ax.set_ylim(-float(ax_ysize),0.)
legend_text_size,legend_text_padding = self.__get_legend_text_size()
legend_text_size_point = pixelToPoint(legend_text_size,dpi)
box_width = legend_text_size
legend_offset = (ax_xsize - nColumns*self.column_width)/2
nc = 0
#self.labels.reverse()
for label,num in self.labels:
num_flag = self.prefs.get('legend_numbers',True)
percent_flag = self.prefs.get('legend_unit','')
if num_flag:
if percent_flag == "%":
num = "%.1f" % num +'%'
else:
num = "%.1f" % num
else:
num = None
color = self.palette.getColor(label)
row = nc%nRows
column = nc/nRows
if row == nRows-1 and column == nColumns-1 and nc != nLabels-1:
last_text = '... plus %d more' % (nLabels-nc)
self.ax.text(float(column*self.column_width)+legend_offset,-float(row*1.6*box_width),
last_text,horizontalalignment='left',
verticalalignment='top',size=legend_text_size_point)
break
else:
self.ax.text(float(column*self.column_width)+2.*box_width+legend_offset,-row*1.6*box_width,
str(label),horizontalalignment='left',
verticalalignment='top',size=legend_text_size_point)
if num is not None:
self.ax.text(float((column+1)*self.column_width)-2*box_width+legend_offset,-float(row*1.6*box_width),
str(num),horizontalalignment='right',
verticalalignment='top',size=legend_text_size_point)
box = Rectangle((float(column*self.column_width)+legend_offset,-float(row*1.6*box_width)-box_width),
box_width,box_width)
box.set_ec('black')
box.set_linewidth(pixelToPoint(0.5,dpi))
box.set_fc(color)
self.ax.add_patch(box)
nc += 1
示例2: drawRect
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linewidth [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: __init__
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linewidth [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
示例4: show
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_linewidth [as 别名]
def show(self,ax=None, max_size=None):
''' Draw the persistence diagram
ax: the axis object
'''
# prepare for plotting
if ax is None:
fig = plt.figure()
cmap = plt.cm.summer
ax = fig.add_subplot(111,aspect='equal')
# base coordinates
centers_x = np.array(range(1,self.n_r+1))
centers_y = np.array(range(self.n_h,-1,-1))
gap_conn = 0.2
gap_disc = 0.4
base_rec_width = gap_disc*2
base_rec_height = gap_disc*2
base_coords_x_left = centers_x-gap_disc
base_coords_x_right = centers_x+gap_disc
base_coords_y_bottom = centers_y-gap_disc
base_coords_y_up = centers_y+gap_disc
# for color
if max_size is None:
colorM = self.sM/float(np.max(self.sM))
else:
colorM = self.sM/float(max_size)
# one rectangle for each clustering
for i in range(self.n_h):
for j in range(self.n_r):
if self.cM[i,j]>0:
x_left = base_coords_x_left[j]
y_bottom = base_coords_y_bottom[i]
rect = Rectangle((x_left,y_bottom),width=base_rec_width, height=base_rec_height,color=cmap(colorM[i,j]))
rect.set_linewidth(0)
ax.add_artist(rect)
# fill up the vertical gaps if necessary
for i in range(self.n_h):
for j in range(1,self.n_r):
if self.cM[i,j]==-1:
continue
if self.cM[i,j-1]==self.cM[i,j]:
x_left = base_coords_x_right[j-1]
y_bottom = base_coords_y_bottom[i]
rect = Rectangle((x_left,y_bottom),width=gap_conn,height=base_rec_height,color=cmap(colorM[i,j]))
rect.set_linewidth(0)
ax.add_artist(rect)
# fill up the horizonal gaps if necessary
# pay attention for a 2x2 block
for i in range(1,self.n_h):
for j in range(self.n_r):
if self.cM[i,j]==-1:
continue
if self.cM[i-1,j]==self.cM[i,j]:
x_left = base_coords_x_left[j]
y_bottom = base_coords_y_up[i]
if (j<(self.n_r-1)) and (self.cM[i,j]==self.cM[i,j+1]) and (self.cM[i,j]==self.cM[i-1,j+1]):
rec_hlen = base_rec_width + gap_conn
else:
rec_hlen = base_rec_width
rect = Rectangle((x_left,y_bottom),width=rec_hlen,height=gap_conn,color=cmap(colorM[i,j]))
rect.set_linewidth(0)
ax.add_artist(rect)
#ax.autoscale_view()
#ax.figure.canvas.draw()
#ax.axis([0, self.n_r+2, 0, self.n_h+2])
#plt.grid(True)
#fig.show()
return fig, ax