本文整理汇总了Python中matplotlib.pyplot.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, xv, yv, mask, **kwargs):
assert xv.shape == yv.shape, 'xv and yv must have the same shape'
for dx, dq in zip(xv.shape, mask.shape):
assert dx==dq+1, \
'''xv and yv must be cell verticies
(i.e., one cell bigger in each dimension)'''
self.xv = xv
self.yv = yv
self.mask = mask
land_color = kwargs.pop('land_color', (0.6, 1.0, 0.6))
sea_color = kwargs.pop('sea_color', (0.6, 0.6, 1.0))
cm = plt.matplotlib.colors.ListedColormap([land_color, sea_color],
name='land/sea')
self._pc = plt.pcolor(xv, yv, mask, cmap=cm, vmin=0, vmax=1, **kwargs)
self._xc = 0.25*(xv[1:,1:]+xv[1:,:-1]+xv[:-1,1:]+xv[:-1,:-1])
self._yc = 0.25*(yv[1:,1:]+yv[1:,:-1]+yv[:-1,1:]+yv[:-1,:-1])
if isinstance(self.xv, np.ma.MaskedArray):
self._mask = mask[~self._xc.mask]
else:
self._mask = mask.flatten()
plt.connect('button_press_event', self._on_click)
plt.connect('key_press_event', self._on_key)
self._clicking = False
plt.title('Editing %s -- click "e" to toggle' % self._clicking)
plt.draw()
示例2: analisis_grafica
def analisis_grafica(carpeta, nombre):
fig = plt.figure()
ax = plt.subplot(111)
# prueba=cm.comtrade(carpeta, nombre)
# prueba.config()
# prueba.extraerDatos()
# A=prueba.oscilografia[:,11]
# B=prueba.oscilografia[:,10]
# C=prueba.oscilografia[:,9]
plt.plot(A, "g", label="A")
plt.plot(B, "r", label="B")
plt.plot(C, "y", label="C")
plt.suptitle(u"Seleccione el ciclo prefalla") # Ponemos un titulo superior
plt.legend() # Creamos la caja con la leyenda
binding_id = plt.connect("motion_notify_event", on_move)
plt.connect("button_press_event", on_click)
"""if "test_disconnect" in sys.argv:
print("disconnecting console coordinate printout...")
plt.disconnect(binding_id)"""
# plt.ion() # Ponemos el modo interactivo
# plt.axvspan(-0.5,0.5, alpha = 0.25)
plt.show()
示例3: twoDplots
def twoDplots(self, ind1, ind2):
"""
Provides a plot of a two-dimensional slice of eigenvector space.
"""
afs = []
fig = plt.figure()
s1 = fig.add_subplot(111)
s1.scatter(self.eigvecs[:, ind1], self.eigvecs[:, ind2], c="w")
afs.append(
AnnoteModule.AnnoteFinder(self.eigvecs[:, ind1], self.eigvecs[:, ind2], self.resnames, xtol=5, ytol=5)
)
plt.connect("button_press_event", afs[-1])
s1.set_xlabel("$|" + str(ind1) + ">$")
s1.set_ylabel("$|" + str(ind2) + ">$")
# fig.suptitle('Eigenvector projections')
try:
for sec in self.listofsecs:
s1.scatter(
self.eigvecs[sec.members, ind1],
self.eigvecs[sec.members, ind2],
c=sec.weights,
cmap=sec.seccolor,
norm=matplotlib.colors.Normalize(vmin=0, vmax=0.3),
)
except AttributeError:
print "No sectors have been defined for this matrix yet. Call twoDxcc to get them if desired."
return fig
示例4: analisis_grafica
def analisis_grafica(self):
#prueba=cm.comtrade(carpeta, nombre)
#prueba.config()
#prueba.extraerDatos()
#A=prueba.oscilografia[:,11]
#B=prueba.oscilografia[:,10]
#C=prueba.oscilografia[:,9]
alt.plot(self.A,'g',label='A')
alt.plot(self.B,'r',label='B')
alt.plot(self.C,'y',label='C')
alt.suptitle(u'Seleccione el ciclo prefalla') # Ponemos un titulo superior
alt.legend() # Creamos la caja con la leyenda
binding_id = alt.connect('motion_notify_event', on_move)
alt.connect('button_press_event', on_click)
'''if "test_disconnect" in sys.argv:
print("disconnecting console coordinate printout...")
plt.disconnect(binding_id)'''
#plt.ion() # Ponemos el modo interactivo
#plt.axvspan(-0.5,0.5, alpha = 0.25)
alt.show()
示例5: ROI_define
def ROI_define():
im=mpimg.imread(image)
height=im.shape[0] / nrow
width=im.shape[1] / ncol
# Axis adjustable in function of views during acquisition
fig=plt.figure(figsize=(10, 10 * height / width))
plt.imshow(im)
plt.grid(True)
plt.xticks([width * i for i in range(1, ncol)])
plt.yticks([height * i for i in range(1, nrow)])
# Add mouse click event to set area of interest
ax2=fig.add_subplot(111)
ax2.patch.set_alpha(0.5)
cnv=Canvas(ax2)
plt.connect('button_press_event', cnv.update_path)
plt.connect('motion_notify_event', cnv.set_location)
plt.show()
# Deal with polygon
poly=cnv.extract_poly()
poly, scaleX, scaleY=coordinate_conversion(
poly, im.shape[1], im.shape[0])
return poly, scaleX, scaleY
示例6: plot
def plot(self, multiview=False):
"""
Plotten der Oberflaeche:
plot(multiview=False)
multiview: True: Two plotfields side by side; False: One single plotfield
- Space-bar: show next surface.
- '[1-9]': show every 2nd surface
- '0': show last surface
- 'r': show first surface
- 'a': switch plot aspect 1:1 <==> auto
- 'c': switch between two modi, single plot, multiple plot for surfaces
- 'f': save plot as (png-)file with the name of the xxx.srf file
- 'b': switch between fixed axis and auto axis of new surface
- 'q': Quit.
"""
help(plot.plot)
if not multiview:
self.multi = False
self.ax1 = plt.subplot(1, 1, 1)
else:
self.multi = True
self.ax1 = plt.subplot(1, 2, 1)
self.ax2 = plt.subplot(1, 2, 2)
self.event_handler(None)
plt.connect("key_press_event", self.event_handler)
plt.show()
示例7: imrect
def imrect(image):
"""
Best python hack of MATLAB's imrect that I could come up with
:param image: a numpy array
:return: returns the bounds of the selected roi
"""
print('Click and drag to select ROI. Press "Enter" to proceed.')
fig = plt.figure('ROI selection')
plt.imshow(image)
ax = plt.axes()
def nothing(eclick, erelease):
pass
bounds = None
def on_enter(event):
if event.key == 'enter' and selector._rect_bbox != (0., 0., 0., 1.):
nonlocal bounds
bounds = [int(i) for i in selector._rect_bbox]
plt.close(fig)
selector = widgets.RectangleSelector(ax, nothing, drawtype='box', interactive=True)
plt.connect('key_press_event', on_enter)
plt.show() # blocks execution until on_enter() completes
return bounds
示例8: plot_vi_breakdown_panel
def plot_vi_breakdown_panel(px, h, title, xlab, ylab, hlines, scatter_size,
**kwargs):
"""Plot a single panel (over or undersegmentation) of VI breakdown plot.
Parameters
----------
px : np.ndarray of float, shape (N,)
The probability (size) of each segment.
h : np.ndarray of float, shape (N,)
The conditional entropy of that segment.
title, xlab, ylab : string
Parameters for `matplotlib.plt.plot`.
hlines : iterable of float
Plot hyperbolic lines of same VI contribution. For each value `v` in
`hlines`, draw the line `h = v/px`.
scatter_size : int, optional
**kwargs : dict
Additional keyword arguments for `matplotlib.pyplot.plot`.
Returns
-------
None
"""
x = np.arange(max(min(px),1e-10), max(px), (max(px)-min(px))/100.0)
for val in hlines:
plt.plot(x, val/x, color='gray', ls=':', **kwargs)
plt.scatter(px, h, label=title, s=scatter_size, **kwargs)
# Make points clickable to identify ID. This section needs work.
af = AnnotationFinder(px, h, [str(i) for i in range(len(px))])
plt.connect('button_press_event', af)
plt.xlim(xmin=-0.05*max(px), xmax=1.05*max(px))
plt.ylim(ymin=-0.05*max(h), ymax=1.05*max(h))
plt.xlabel(xlab)
plt.ylabel(ylab)
plt.title(title)
示例9: turnon
def turnon(self, event, current_ax):
self.Fiddle = True
toggle_selector.RS = RectangleSelector(current_ax, self.line_select_callback,
drawtype='box', useblit=True,
button=[3], # don't use middle button
minspanx=5, minspany=5,
spancoords='pixels')
plt.connect('key_press_event', toggle_selector)
示例10: view
def view(self,comparer=None,grayScale=False):
self.grayScale= grayScale
self.comparer = comparer
self.fig = plt.figure("Image Viewer")
self.ax = plt.subplot(111)
self._event_fct(None) # initial setup
plt.connect('key_press_event', self._event_fct)
plt.show()
示例11: configureFigure
def configureFigure(self):
#http://stackoverflow.com/questions/12439588/how-to-maximize-a-plt-show-window-using-python
mng = plt.get_current_fig_manager()
#mng.resize(*mng.window.maxsize())
mng.window.wm_geometry("+0+0")
#http://stackoverflow.com/questions/6541123/improve-subplot-size-spacing-with-many-subplots-in-matplotlib
plt.subplots_adjust(left=0.09, right=0.95, bottom=0.05, top=0.95, wspace=0.2, hspace=0.5)
#http://matplotlib.org/examples/event_handling/keypress_demo.html
plt.connect('key_press_event', pressHandler)
示例12: __init__
def __init__(self, environment):
self.signal = False
self.environment = environment
plt.ion()
plt.axis([0,environment.width,0,environment.height])
plt.connect('key_press_event', self.event)
plt.show()
self.draw()
plt.pause(100)
示例13: point
def point(x,y,annotation,r,p,c,cmap,ytol):
a=[x]
b=[y]
n=[annotation]
s=[r*r]
color=matplotlib.colors.colorConverter.to_rgb(cmap(1.+log10(c)))
#sctpt=ax.scatter(a,b,s=s,color=color,cmap=cmap,edgecolors='black')
sctpt=pylab.gca().scatter(a,b,s=s,color=color,cmap=cmap,alpha=1.,picker=5)
af1 = AnnoteFinder(a,b,n,xtol=r,ytol=ytol,pos=p)
P.connect('button_press_event',af1)
return sctpt
示例14: signalPlot
def signalPlot(time, data, names):
plt.figure(1)
colors =['r', '#FCBDB1', 'g', '#B6FAC4', 'b', '#CAB6FA', 'c']
ax = plt.subplot(111)
for x in range(len(data)):
ax.plot(time, data[x], c=colors[x], label=names[x])
plt.legend()
selector.keyPressed.RS = RectangleSelector(ax, selector.onselect, drawtype='box', rectprops=dict(facecolor='red', edgecolor = 'black',
alpha=0.5, fill=True))
plt.connect('key_press_event', selector.keyPressed)
plt.show()
plt.show()
示例15: plotEvents
def plotEvents(catalog, client=None, **kwargs):
"""
Plot events on map.
When client is given it shows the waveform when the event is clicked.
IPython may not be started in pylab mode for this feature working.
"""
def onpress(event):
if not event.inaxes or event.key != "shift":
return
lon, lat = map(event.xdata, event.ydata, inverse=True)
dlon = 0.05
dlat = 0.05
filter = "%f < latitude < %f and %f < longitude < %f" % (lat - dlat, lat + dlat, lon - dlon, lon + dlon)
ev = catalog.filter2(filter)
if len(ev) == 0:
print "No event picked"
return
from sito import Stream
st = Stream()
print "Selcet", ev
for arrival in ev[0].origins[0].arrivals:
arrival.pick_id.convertIDToQuakeMLURI()
pick = arrival.pick_id.getReferredObject()
if not pick:
print "FAIL"
return
time = pick.time
seed_id = pick.waveform_id.getSEEDString()
try:
st1 = Stream(client.getWaveform(*(seed_id.split(".") + [time - 50, time + 250])))
except Exception as ex:
print "%s for %s" % (ex, seed_id)
continue
st1.merge()
print "load %s %s %.1f" % (seed_id, pick.phase_hint, time - ev[0].origins[0].time)
st1[0].stats["label"] = "%s %s %.1f" % (seed_id, pick.phase_hint, time - ev[0].origins[0].time)
st += st1
st.setHI("filter", "")
st.filter2(2, None)
# st.plot(automerge=False, method='fast', type='relative')
im = st.plot_()
plt.show()
if client is None:
catalog.plot(**kwargs)
else:
map, ax = catalog.plot(handle=True, **kwargs)
plt.connect("button_press_event", onpress)
plt.show()