本文整理汇总了Python中matplotlib.patches.Polygon.set_alpha方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.set_alpha方法的具体用法?Python Polygon.set_alpha怎么用?Python Polygon.set_alpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Polygon
的用法示例。
在下文中一共展示了Polygon.set_alpha方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plotReachSet_norm1
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_alpha [as 别名]
def plotReachSet_norm1(self, NUM, figname):
fig = p.figure()
for j in range(n):
ax = fig.add_subplot(2,2,j+1 , aspect='equal')
ax.set_xlim(0, 4)
ax.set_ylim(0, 1)
ax.set_xlabel('$x_'+str(j+1)+'$')
ax.set_ylabel('$y_'+str(j+1)+'$')
for trace in self:
for i in [int(floor(k*len(trace.T)/NUM)) for k in range(NUM)]:
verts = [(trace.x[i][j] + 1/trace.d_norm1[i][2*j], trace.y[i][j] ),
(trace.x[i][j] , trace.y[i][j] - 1/trace.d_norm1[i][2*j+1]),
(trace.x[i][j] - 1/trace.d_norm1[i][2*j], trace.y[i][j] ),
(trace.x[i][j] , trace.y[i][j] + 1/trace.d_norm1[i][2*j+1])]
# poly = Ellipse((trace.x[i][j],trace.y[i][j]), width=trace.d1[i], height=trace.d2[i], angle=trace.theta[i])
poly = Polygon(verts, facecolor='0.8', edgecolor='k')
ax.add_artist(poly)
poly.set_clip_box(ax.bbox)
poly.set_alpha(1)
if i==0:
poly.set_facecolor('r')
else:
poly.set_facecolor(p.rand(3))
#for trace in self:
#e = Ellipse((trace.x[0][j],trace.y[0][j]), width=trace.d1[0], height=trace.d2[0], angle=trace.theta[0])
#ax.add_artist(e)
#e.set_clip_box(ax.bbox)
#e.set_alpha(1)
#e.set_facecolor('r')
#e.set_edgecolor('r')
p.savefig(figname)
示例2: fill_between
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_alpha [as 别名]
def fill_between(x, y1, y2, ax=P.gca(), alpha=0.5, **kwargs):
"""Plot distribution to a head surface, derived from some sensor locations.
The sensor locations are first projected onto the best fitting sphere and
finally projected onto a circle (by simply ignoring the z-axis).
:Parameters:
x:
,y1,y2
ax: mpl axes
axes to plot to. Standard is pylab.
view: one of 'top' and 'rear'
Defines from where the head is viewed.
**kwargs:
All additional arguments will be passed to `pylab.imshow()`.
:Returns:
(map, head, sensors)
The corresponding matplotlib objects are returned if plotted, ie.
if plothead is set to `False`, `head` will be `None`.
map
The colormap that makes the actual plot, a
matplotlib.image.AxesImage instance.
head
What is returned by `plot_head_outline()`.
sensors
The dots marking the electrodes, a matplotlib.lines.Line2d
instance.
"""
# add x,y2 in reverse order for proper polygon filling
verts = zip(x,y1) + [(x[i], y2[i]) for i in range(len(x)-1,-1,-1)]
poly = Polygon(verts, **kwargs)
poly.set_alpha(alpha)
ax.add_patch(poly)
ax.autoscale_view()
return poly
示例3: PolygonInteractor
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_alpha [as 别名]
class PolygonInteractor(QtCore.QObject):
"""
Polygon Interactor
Parameters
----------
axtmp : matplotlib axis
matplotlib axis
pntxy :
"""
showverts = True
epsilon = 5 # max pixel distance to count as a vertex hit
polyi_changed = QtCore.pyqtSignal(list)
def __init__(self, axtmp, pntxy):
QtCore.QObject.__init__(self)
self.ax = axtmp
self.poly = Polygon([(1, 1)], animated=True)
self.ax.add_patch(self.poly)
self.canvas = self.poly.figure.canvas
self.poly.set_alpha(0.5)
self.pntxy = pntxy
self.ishist = True
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
xtmp, ytmp = list(zip(*self.poly.xy))
self.line = Line2D(xtmp, ytmp, marker='o', markerfacecolor='r',
color='y', animated=True)
self.ax.add_line(self.line)
self.poly.add_callback(self.poly_changed)
self._ind = None # the active vert
self.canvas.mpl_connect('button_press_event',
self.button_press_callback)
self.canvas.mpl_connect('button_release_event',
self.button_release_callback)
self.canvas.mpl_connect('motion_notify_event',
self.motion_notify_callback)
def draw_callback(self):
""" Draw callback """
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
QtWidgets.QApplication.processEvents()
self.canvas.restore_region(self.background)
self.ax.draw_artist(self.poly)
self.ax.draw_artist(self.line)
self.canvas.update()
def new_poly(self, npoly):
""" New Polygon """
self.poly.set_xy(npoly)
self.line.set_data(list(zip(*self.poly.xy)))
self.canvas.draw()
self.update_plots()
def poly_changed(self, poly):
""" Changed Polygon """
# this method is called whenever the polygon object is called
# only copy the artist props to the line (except visibility)
vis = self.line.get_visible()
Artist.update_from(self.line, poly)
self.line.set_visible(vis) # don't use the poly visibility state
def get_ind_under_point(self, event):
"""get the index of vertex under point if within epsilon tolerance"""
# display coords
xytmp = np.asarray(self.poly.xy)
xyt = self.poly.get_transform().transform(xytmp)
xtt, ytt = xyt[:, 0], xyt[:, 1]
dtt = np.sqrt((xtt - event.x) ** 2 + (ytt - event.y) ** 2)
indseq = np.nonzero(np.equal(dtt, np.amin(dtt)))[0]
ind = indseq[0]
if dtt[ind] >= self.epsilon:
ind = None
return ind
def button_press_callback(self, event):
"""whenever a mouse button is pressed"""
if event.inaxes is None:
return
if event.button != 1:
return
self._ind = self.get_ind_under_point(event)
if self._ind is None:
xys = self.poly.get_transform().transform(self.poly.xy)
ptmp = event.x, event.y # display coords
if len(xys) == 1:
self.poly.xy = np.array(
[(event.xdata, event.ydata)] +
[(event.xdata, event.ydata)])
#.........这里部分代码省略.........
示例4: zip
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_alpha [as 别名]
m.drawparallels(np.arange(20,80,5),labels=[1,0,0,0],fmt=lat2str(), dashes=[2,0], linewidth=0.5)
m.drawmeridians(np.arange(-20,60,5),labels=[0,0,0,1],fmt=lon2str(), dashes=[2,0], linewidth=0.5)
shp_info = m.readshapefile('cities','cities')
x, y = zip(*m.cities)
m.scatter(x,y,15,marker='o',edgecolors='k',color='none',zorder=10)
print m.proj4string
shp_info = m.readshapefile('polygon','sectors',drawbounds=True, color='r')
ax = plt.gca() # get current axes instance
for nshape,seg in enumerate(m.sectors):
color = "#F9966B"
poly = Polygon(seg,facecolor=color,edgecolor=color)
poly.set_alpha(0.75)
ax.add_patch(poly)
# m.drawlsmask(ocean_color='0.3', lakes=True)
m.fillcontinents(color='0.9', zorder=0)
plt.savefig('008_map_laea.png', dpi=72)
plt.savefig('008_map_laea_big.png', dpi=108)
# create new figure
fig=plt.figure(figsize=(8,5))
# setup oblique mercator basemap.
m = Basemap(projection='cyl',llcrnrlat=35,urcrnrlat=65,\
llcrnrlon=-10,urcrnrlon=45,resolution='l')