本文整理汇总了Python中matplotlib.collections.RegularPolyCollection类的典型用法代码示例。如果您正苦于以下问题:Python RegularPolyCollection类的具体用法?Python RegularPolyCollection怎么用?Python RegularPolyCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RegularPolyCollection类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: add_squares
def add_squares(treeplot, nodes, colors='r', size=15, xoff=0, yoff=0, alpha=1.0,
vis=True):
"""
Draw a square at given node
Args:
p: A node or list of nodes or string or list of strings
colors: Str or list of strs. Colors of squares to be drawn.
Optional, defaults to 'r' (red)
size (float): Size of the squares. Optional, defaults to 15
xoff, yoff (float): Offset for x and y dimensions. Optional,
defaults to 0.
alpha (float): between 0 and 1. Alpha transparency of squares.
Optional, defaults to 1 (fully opaque)
zorder (int): The drawing order. Higher numbers appear on top
of lower numbers. Optional, defaults to 1000.
"""
points = xy(treeplot, nodes)
trans = offset_copy(
treeplot.transData, fig=treeplot.figure, x=xoff, y=yoff, units='points')
col = RegularPolyCollection(
numsides=4, rotation=pi*0.25, sizes=(size*size,),
offsets=points, facecolors=colors, transOffset=trans,
edgecolors='none', alpha=alpha, zorder=1
)
col.set_visible(vis)
treeplot.add_collection(col)
treeplot.figure.canvas.draw_idle()
开发者ID:ChriZiegler,项目名称:ivy,代码行数:31,代码来源:layers.py
示例2: __init__
class LassoManager:
def __init__(self, ax, data,labels=None, color_on='r', color_off='k'):
self.axes = ax
self.canvas = ax.figure.canvas
self.data = data
self.call_list = []
self.Nxy = data.shape[0]
self.color_on = colorConverter.to_rgba(color_on)
self.color_off = colorConverter.to_rgba(color_off)
facecolors = [self.color_on for _ in range(self.Nxy)]
fig = ax.figure
self.collection = RegularPolyCollection(
fig.dpi, 6, sizes=(1,),
facecolors=facecolors,
edgecolors=facecolors,
offsets = self.data,
transOffset = ax.transData)
ax.add_collection(self.collection, autolim=True)
ax.autoscale_view()
if labels is not None:
ax.set_xlabel(labels[0])
ax.set_ylabel(labels[1])
self.cid = self.canvas.mpl_connect('button_press_event', self.onpress)
self.ind = None
self.canvas.draw()
def register(self, callback_func):
self.call_list.append(callback_func)
def callback(self, verts):
facecolors = self.collection.get_facecolors()
edgecolors = self.collection.get_edgecolors()
ind = nonzero(points_inside_poly(self.data, verts))[0]
for i in range(self.Nxy):
if i in ind:
facecolors[i] = self.color_on
edgecolors[i] = self.color_on
else:
facecolors[i] = self.color_off
edgecolors[i] = self.color_off
self.canvas.draw_idle()
self.canvas.widgetlock.release(self.lasso)
del self.lasso
self.ind = ind
for func in self.call_list:
func(ind)
def onpress(self, event):
if self.canvas.widgetlock.locked(): return
if event.inaxes is None: return
self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback)
# acquire a lock on the widget drawing
self.canvas.widgetlock(self.lasso)
开发者ID:belevtsoff,项目名称:SpikeSort,代码行数:59,代码来源:manual_sort.py
示例3: __init__
def __init__(self, ax, data):
self.axes = ax
self.canvas = ax.figure.canvas
self.data = data
#the lasso lock boolean is used to tell whether another
#widget event has priority
self.lassoLock = False
self.Nxy = len(data)
facecolors = [d.color for d in data]
self.xys = [(d.x, d.y) for d in data]
fig = ax.figure
self.collection = RegularPolyCollection(
fig.dpi, 6, sizes=(100,),
facecolors=facecolors,
offsets = self.xys,
transOffset = ax.transData)
ax.add_collection(self.collection)
self.cid = self.canvas.mpl_connect('button_press_event', self.onpress)
self.cidRelease = self.canvas.mpl_connect('button_release_event', self.onrelease)
self.ind = None
开发者ID:DavidB-CMU,项目名称:moped,代码行数:25,代码来源:lasso.py
示例4: __init__
def __init__(self, df, ax=None, xcol='x', ycol='y', callback=None):
self.df = df
self.ax = ax or pl.gca()
self.canvas = ax.figure.canvas
self.lasso_lock = False # indicates if another widget event has priority
self.idxs = array(list(self.df.T)) # look up parallel with point indices
self.xys = df[[xcol, ycol]].values
self.xcol = xcol
self.ycol = ycol
# timv: don't think this PolyCollection is needed..
self.collection = RegularPolyCollection(numsides=ax.figure.dpi,
rotation=6,
sizes=(100,),
facecolors = [to_rgba('green', alpha=0.0)]*len(self.xys),
linewidths = 0,
offsets = self.xys,
transOffset = ax.transData)
ax.add_collection(self.collection)
self.user_callback = callback
self.canvas.mpl_connect('key_press_event', self.onpress)
self.canvas.mpl_connect('button_press_event', self.onpress)
self.canvas.mpl_connect('button_release_event', self.onrelease)
self.selected = None
self.lasso = None
开发者ID:timvieira,项目名称:viz,代码行数:26,代码来源:lasso.py
示例5: __init__
def __init__(self, ax, data, fs_list, plkwargs, max_collection=500):
if pyfusion.VERBOSE>2:
print("init, fs_list size=%d" % (len(fs_list)))
self.axes = ax
self.canvas = ax.figure.canvas
self.data = data
self.fs_list = fs_list
self.plkwargs = plkwargs
self.Nxy = len(data)
facecolors = [d.color for d in data]
self.xys = [(d.x, d.y) for d in data]
fig = ax.figure
# here we define the polygons that indicate that a point is registered
# - use empty triangles for simplicity and speed
# skip altogether if there are too many
# not sure how much this saves - each point still is a datum
if (self.Nxy<max_collection):
self.collection = RegularPolyCollection(
3, 0, sizes=(100,),facecolors='', edgecolors=facecolors,
offsets = self.xys, transOffset = ax.transData)
ax.add_collection(self.collection)
else: self.collection = None
self.cid = self.canvas.mpl_connect('button_press_event', self.onpress)
print("connected cid=%d" % (self.cid) )
self.ind = None
开发者ID:bdb112,项目名称:pyfusion,代码行数:30,代码来源:lasso_fs_init.py
示例6: LassoManager
class LassoManager(object):
def __init__(self, ax, data):
self.axes = ax
self.canvas = ax.figure.canvas
self.data = data
self.Nxy = len(data)
facecolors = [d.color for d in data]
self.xys = [(d.x, d.y) for d in data]
fig = ax.figure
self.collection = RegularPolyCollection(
fig.dpi, 6, sizes=(100,),
facecolors=facecolors,
offsets=self.xys,
transOffset=ax.transData)
ax.add_collection(self.collection)
self.cid = self.canvas.mpl_connect('button_press_event', self.onpress)
def callback(self, verts):
facecolors = self.collection.get_facecolors()
p = path.Path(verts)
ind = p.contains_points(self.xys)
for i in range(len(self.xys)):
if ind[i]:
facecolors[i] = Datum.colorin
else:
facecolors[i] = Datum.colorout
self.canvas.draw_idle()
self.canvas.widgetlock.release(self.lasso)
del self.lasso
def onpress(self, event):
if self.canvas.widgetlock.locked():
return
if event.inaxes is None:
return
self.lasso = Lasso(event.inaxes,
(event.xdata, event.ydata),
self.callback)
# acquire a lock on the widget drawing
self.canvas.widgetlock(self.lasso)
开发者ID:7924102,项目名称:matplotlib,代码行数:45,代码来源:lasso_demo.py
示例7: build_collection
def build_collection(self):
self.point_size = self.sl_x2_pointsize.GetValue() + 50 # range 50 to 300
self.collection = RegularPolyCollection(
#self.axes.figure.dpi,
numsides = 80,
sizes=(self.point_size,),
facecolors=self.color_array,
offsets = self.data_array,
transOffset = self.axes.transData)
self.collection.set_alpha(0.7)
self.axes.add_collection(self.collection)
#self.axes.axis([self.xmin, self.xmax, self.ymin, self.ymax])
self.axes.autoscale_view()
x = self.axes.get_xaxis()
y = self.axes.get_yaxis()
x.zoom(-1)
y.zoom(-1)
开发者ID:Alwnikrotikz,项目名称:turnip-town,代码行数:18,代码来源:x2.py
示例8: MainPanel
#.........这里部分代码省略.........
pre_data_array, self.song_array, self.color_array, use_std = GetResultsArray(selected_array)
#print pre_data_array
pca1, pca2, pca3 = pca_module.PCA_svd(pre_data_array, use_std)
#print self.data_array
#print pca1
#self.data = pca1
#print pca2
#grab the first 2 components
self.data_array = np.array_split(pca1,[2,],axis=1)[0]
#print self.data_array
#self.axes.set_xlabel(r'$\Delta_i$', fontsize=20)
#self.axes.set_ylabel(r'$\Delta_{i+1}$', fontsize=20)
#self.axes.set_title('Volume and percent change')
#self.axes.grid(True)
### use zoom instead
#self.xmin = self.data1.min()# - (self.data1.max() * 0.1)
#self.xmax = self.data1.max()# * 1.1
#self.ymin = self.data2.min()# - (self.data2.max() * 0.1)
#self.ymax = self.data2.max()# * 1.1
def build_graph(self):
self.axes = self.figure.add_subplot(111, axisbg=(1,1,1))
self.figure.subplots_adjust(left=0, right=1, top=1, bottom=0)
#self.axes.frame_on(False)
#subplot(111, axisbg='darkslategray')
#ax = fig.add_subplot(111)
#self.axes.scatter(self.data2, self.data1, c=[0.5,0.5,1.0], s=200, alpha=0.5)
def build_collection(self):
self.point_size = self.sl_x2_pointsize.GetValue() + 50 # range 50 to 300
self.collection = RegularPolyCollection(
#self.axes.figure.dpi,
numsides = 80,
sizes=(self.point_size,),
facecolors=self.color_array,
offsets = self.data_array,
transOffset = self.axes.transData)
self.collection.set_alpha(0.7)
self.axes.add_collection(self.collection)
#self.axes.axis([self.xmin, self.xmax, self.ymin, self.ymax])
self.axes.autoscale_view()
x = self.axes.get_xaxis()
y = self.axes.get_yaxis()
x.zoom(-1)
y.zoom(-1)
#self.axes.axis('tight')
##self.axes.axis('off')
def callback(self, verts):
facecolors = self.collection.get_facecolors()
ind = nonzero(points_inside_poly(self.data_array, verts))[0]
for i in range(len(self.data_array)):
if i in ind:
facecolors[i] = (1,1,0,.5)
#print facecolors[i]
#pass
else:
facecolors[i] = self.color_array[i]
#pass
#print facecolors[i]
self.canvas.draw_idle()
开发者ID:Alwnikrotikz,项目名称:turnip-town,代码行数:67,代码来源:x2.py
示例9: LassoBrowser
class LassoBrowser(object):
def __init__(self, df, ax=None, xcol='x', ycol='y', callback=None):
self.df = df
self.ax = ax or pl.gca()
self.canvas = ax.figure.canvas
self.lasso_lock = False # indicates if another widget event has priority
self.idxs = array(list(self.df.T)) # look up parallel with point indices
self.xys = df[[xcol, ycol]].values
self.xcol = xcol
self.ycol = ycol
# timv: don't think this PolyCollection is needed..
self.collection = RegularPolyCollection(numsides=ax.figure.dpi,
rotation=6,
sizes=(100,),
facecolors = [to_rgba('green', alpha=0.0)]*len(self.xys),
linewidths = 0,
offsets = self.xys,
transOffset = ax.transData)
ax.add_collection(self.collection)
self.user_callback = callback
self.canvas.mpl_connect('key_press_event', self.onpress)
self.canvas.mpl_connect('button_press_event', self.onpress)
self.canvas.mpl_connect('button_release_event', self.onrelease)
self.selected = None
self.lasso = None
def lasso_callback(self, verts):
if verts is not None and len(verts):
[selected] = nonzero(points_inside_poly(self.xys, verts))
else:
selected = []
# change face colors inplace
facecolors = self.collection.get_facecolors()
facecolors[:] = to_rgba('green', alpha=0.0)
facecolors[selected] = to_rgba('yellow', alpha=0.6)
# convert from point indices to dataframe indices
idx = self.idxs[selected]
m = self.df.ix[idx] # show selected rows of dataframe
if self.user_callback is None:
print m
else:
self.user_callback(m)
self.canvas.draw_idle()
self.canvas.widgetlock.release(self.lasso)
self.selected = selected
def onpress(self, event):
if self.canvas.widgetlock.locked():
return
if event.inaxes is None:
return
if event.key in ('escape',):
self.selected = []
self.lasso_callback([])
return
# TODO: implement zoom out as undo.
# zoom in to selection
if event.key in ('+', '='):
selected_rows = self.df.ix[self.selected]
xs = selected_rows[self.xcol]
ys = selected_rows[self.ycol]
self.ax.set_xlim(xs.min(), xs.max())
self.ax.set_ylim(ys.min(), ys.max())
self.canvas.draw()
return
self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.lasso_callback)
self.canvas.widgetlock(self.lasso) # acquire lock on lasso widget
self.lasso_lock = True # used when we release
def onrelease(self, event):
'on release we reset the press data'
# test whether the widgetlock was initiated by the lasso
if self.lasso_lock:
self.canvas.widgetlock.release(self.lasso)
self.lasso_lock = False
开发者ID:timvieira,项目名称:viz,代码行数:85,代码来源:lasso.py
注:本文中的matplotlib.collections.RegularPolyCollection类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论