本文整理汇总了Python中matplotlib.collections.RegularPolyCollection.get_facecolors方法的典型用法代码示例。如果您正苦于以下问题:Python RegularPolyCollection.get_facecolors方法的具体用法?Python RegularPolyCollection.get_facecolors怎么用?Python RegularPolyCollection.get_facecolors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.RegularPolyCollection
的用法示例。
在下文中一共展示了RegularPolyCollection.get_facecolors方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.collections import RegularPolyCollection [as 别名]
# 或者: from matplotlib.collections.RegularPolyCollection import get_facecolors [as 别名]
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)
示例2: __init__
# 需要导入模块: from matplotlib.collections import RegularPolyCollection [as 别名]
# 或者: from matplotlib.collections.RegularPolyCollection import get_facecolors [as 别名]
class LassoManager:
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
def callback(self, verts):
facecolors = self.collection.get_facecolors()
ind = nonzero(points_inside_poly(self.xys, verts))[0]
for i in range(self.Nxy):
if i in ind:
facecolors[i] = Datum.colorin
else:
facecolors[i] = Datum.colorout
self.canvas.draw_idle()
self.canvas.widgetlock.release(self.lasso)
#del self.lasso
self.ind = 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)
# establish boolean that can be used to release the widgetlock
self.lassoLock = True
def onrelease(self, event):
'on release we reset the press data'
# test whether the widgetlock was initiated by the lasso
if self.lassoLock:
self.canvas.widgetlock.release(self.lasso)
self.lassoLock = False
print self.ind
示例3: LassoManager
# 需要导入模块: from matplotlib.collections import RegularPolyCollection [as 别名]
# 或者: from matplotlib.collections.RegularPolyCollection import get_facecolors [as 别名]
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)
示例4: MainPanel
# 需要导入模块: from matplotlib.collections import RegularPolyCollection [as 别名]
# 或者: from matplotlib.collections.RegularPolyCollection import get_facecolors [as 别名]
#.........这里部分代码省略.........
#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()
self.canvas.widgetlock.release(self.lasso)
del self.lasso
#self.ind = ind
self.pass_data(ind)
def onpress(self, event):
#print event.button
if self.canvas.widgetlock.locked():
#print 'foo'
self.canvas.widgetlock.release(self.lasso)
#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)
def pass_data(self, ind):
#populate parents list control
self.lc_x2_plist.DeleteAllItems()
for x in ind:
self.lc_x2_plist.InsertStringItem(0, self.song_array[x][0])
self.lc_x2_plist.SetStringItem(0, 1, self.song_array[x][1])
#pass
def update_data(self):
pass
#self.figure.clf()
#build_graph(self)
#self.MakeScatt()
#self.build_collection()
def OnAutoGenerateX2Playist(self, event):
# copy the sifted list to the playlist
self.parent.CheckClear()
insert_at = self.parent.lc_playlist.GetItemCount()
for x in range(self.lc_x2_plist.GetItemCount(), 0, -1):
artist = self.lc_x2_plist.GetItem(x-1, 0).GetText()
song = self.lc_x2_plist.GetItem(x-1, 1).GetText()
self.parent.SetPlaylistItem(insert_at, artist, song, '', '')
#save the playlist
self.parent.SavePlaylist()
# switch tabs
self.parent.nb_main.SetSelection(self.nb_playlist)
示例5: LassoBrowser
# 需要导入模块: from matplotlib.collections import RegularPolyCollection [as 别名]
# 或者: from matplotlib.collections.RegularPolyCollection import get_facecolors [as 别名]
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