本文整理汇总了Python中matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg.mpl_connect方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasGTK3Agg.mpl_connect方法的具体用法?Python FigureCanvasGTK3Agg.mpl_connect怎么用?Python FigureCanvasGTK3Agg.mpl_connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg
的用法示例。
在下文中一共展示了FigureCanvasGTK3Agg.mpl_connect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import mpl_connect [as 别名]
def __init__(self, model=None, parent=None):
#View.__init__(self, model=model, parent=parent)
if mdli.IProject.providedBy(model):
model=None
View.__init__(self, model=model, parent=parent)
self.plot_options={'show-lines':True}
self.set_axis_labels()
#self.ui=rakeviews.Ui()
self.ui.win=Gtk.Frame()
#parent_ui= ui = parent.ui #gsm().getUtility(rakeints.IApplication).ui
parent_ui= ui = gsm().getUtility(rakeints.IApplication).ui
local=rakeviews.Ui()
self.local=local
self.ui.main_frame = win = self.ui.win
win.set_shadow_type(Gtk.ShadowType.NONE)
vbox = Gtk.VBox()
win.add(vbox)
fig = Figure(figsize=(5,4), dpi=120,
subplotpars=matplotlib.figure.SubplotParams(left=0.03, right=0.96, bottom=0.03, top=0.96)
)
self.ui.fig = fig
self.ui.ax = fig.add_subplot(111)
#self.ui.ax2=self.ui.ax.twinx()
#self.ui.ay2=self.ui.ax.twiny()
canvas = FigureCanvas(fig) # a Gtk.DrawingArea
self.ui.canvas = canvas
canvas.set_size_request(600, 400)
vbox.pack_start(canvas, True, True, 0)
toolbar_ = TXRFNavigationToolbar(canvas, self)
self.ui.sb=ui.statusbar
local.msg_id=None
local.ctx_id=self.ui.sb.get_context_id("plotting")
self.ui.cid = canvas.mpl_connect('button_press_event', self.on_click)
示例2: PopUpImage
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import mpl_connect [as 别名]
class PopUpImage(object):
def __init__(self, xdata, ydata, xlabel, ylabel, title):
self.popupwin=Gtk.Window()
self.popupwin.set_size_request(600,550)
self.popupwin.set_position(Gtk.WindowPosition.CENTER)
self.popupwin.set_border_width(10)
self.xdata = xdata
self.ydata = ydata
vbox = Gtk.VBox()
self.fig=Figure(dpi=100)
self.ax = self.fig.add_subplot(111)
self.canvas = FigureCanvas(self.fig)
self.main_figure_navBar = NavigationToolbar(self.canvas, self)
self.cursor = Cursor(self.ax, color='k', linewidth=1, useblit=True)
self.canvas.mpl_connect("button_press_event",self.on_press)
self.ax.set_xlabel(xlabel, fontsize = 18)
self.ax.set_ylabel(ylabel, fontsize = 18)
self.ax.set_title(title, fontsize = 18)
self.ax.plot(self.xdata, self.ydata, 'b-', lw=2)
self.textes = []
self.plots = []
vbox.pack_start(self.main_figure_navBar, False, False, 0)
vbox.pack_start(self.canvas, True, True, 2)
self.popupwin.add(vbox)
self.popupwin.connect("destroy", self.dest)
self.popupwin.show_all()
def dest(self,widget):
self.popupwin.destroy()
def on_press(self, event):
if event.inaxes == self.ax and event.button==3:
self.clear_notes()
xc = event.xdata
#***** Find the closest x value *****
residuel = self.xdata - xc
residuel = N.abs(residuel)
j = N.argmin(residuel)
#y = self.ydata[i-1:i+1]
#yc= y.max()
#j = N.where(self.ydata == yc)
#j = j[0][0]
xc= self.xdata[j]
x_fit = self.xdata[j-3:j+3]
y_fit = self.ydata[j-3:j+3]
fitted_param, fitted_data = fit(x_fit, y_fit, xc, True)
x_fit = N.linspace(x_fit.min(), x_fit.max(), 200)
y_fit = psdVoigt(fitted_param, x_fit)
period = fitted_param['xc'].value
std_err= fitted_param['xc'].stderr
p = self.ax.plot(x_fit, y_fit,'r-')
p2 = self.ax.axvline(period,color='green',lw=2)
txt=self.ax.text(0.05, 0.9, 'Period = %.4f +- %.4f (nm)'%(period, std_err), transform = self.ax.transAxes, color='red')
self.textes.append(txt)
self.plots.append(p[0])
self.plots.append(p2)
elif event.inaxes == self.ax and event.button==2:
dif = N.diff(self.ydata)
dif = dif/dif.max()
p3 = self.ax.plot(dif,'r-')
self.plots.append(p3[0])
self.canvas.draw()
def clear_notes(self):
if len(self.textes)>0:
for t in self.textes:
t.remove()
if len(self.plots)>0:
for p in self.plots:
p.remove()
self.textes = []
self.plots = []
示例3: CampaignGraph
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import mpl_connect [as 别名]
class CampaignGraph(object):
title = 'Unknown'
_graph_id = None
table_subscriptions = []
def __init__(self, config, parent, size_request=None):
self.config = config
self.parent = parent
self.figure, ax = pyplot.subplots()
self.axes = self.figure.get_axes()
self.canvas = FigureCanvas(self.figure)
self.manager = None
if size_request:
self.canvas.set_size_request(*size_request)
self.canvas.mpl_connect('button_press_event', self.mpl_signal_canvas_button_pressed)
self.canvas.show()
self.navigation_toolbar = NavigationToolbar(self.canvas, self.parent)
self.navigation_toolbar.hide()
self.popup_menu = Gtk.Menu.new()
menu_item = Gtk.MenuItem.new_with_label('Export')
menu_item.connect('activate', self.signal_activate_popup_menu_export)
self.popup_menu.append(menu_item)
menu_item = Gtk.MenuItem.new_with_label('Refresh')
menu_item.connect('activate', lambda action: self.refresh())
self.popup_menu.append(menu_item)
menu_item = Gtk.CheckMenuItem.new_with_label('Show Toolbar')
menu_item.connect('toggled', self.signal_toggled_popup_menu_show_toolbar)
self.popup_menu.append(menu_item)
self.popup_menu.show_all()
@classmethod
def get_graph_id(klass):
return klass._graph_id
def make_window(self):
if self.manager == None:
self.manager = FigureManager(self.canvas, 0)
window = self.manager.window
window.set_transient_for(self.parent)
window.set_title(self.title)
return window
def mpl_signal_canvas_button_pressed(self, event):
if event.button != 3:
return
pos_func = lambda m, d: (event.x, event.y, True)
self.popup_menu.popup(None, None, None, None, event.button, Gtk.get_current_event_time())
return True
def signal_activate_popup_menu_export(self, action):
dialog = gui_utilities.UtilityFileChooser('Export Graph', self.parent)
file_name = self.config['campaign_name'] + '.png'
response = dialog.run_quick_save(file_name)
dialog.destroy()
if not response:
return
destination_file = response['target_filename']
self.figure.savefig(destination_file, format='png')
def signal_toggled_popup_menu_show_toolbar(self, widget):
if widget.get_property('active'):
self.navigation_toolbar.show()
else:
self.navigation_toolbar.hide()
def load_graph(self):
self.refresh()
def refresh(self, info_cache=None):
info_cache = (info_cache or {})
if not self.parent.rpc:
return info_cache
for table in self.table_subscriptions:
if not table in info_cache:
info_cache[table] = list(self.parent.rpc.remote_table('campaign/' + table, self.config['campaign_id']))
map(lambda ax: ax.clear(), self.axes)
self._load_graph(info_cache)
self.canvas.draw()
return info_cache
示例4: __init__
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import mpl_connect [as 别名]
class SummaryView:
"""
Display the trends chart and daily summary of weather data.
"""
def __init__(self, single_day_mode: bool = False):
"""
Initialises charting and summary.
:param single_day_mode: Set to true to render
summary of single item(used in historic view).
"""
self.single_day_mode = single_day_mode
self.chart_data = []
self.view = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
self.chart = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
self.summary = Gtk.Box(spacing=10)
self.label = Gtk.Label()
self.label.set_name('f_temp')
# Dynamically create widgets.
self.items = []
for _ in range(1) if single_day_mode else range(5):
item = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
temperature = Gtk.Label()
time = Gtk.Label()
status = Gtk.Image()
temperature.set_name("f_temp")
time.set_name("f_time")
item.pack_start(temperature, False, False, 0)
item.pack_start(status, False, False, 0)
item.pack_start(time, False, False, 0)
self.items.append([status, temperature, time])
self.summary.pack_start(item, True, True, 10)
# Initializing and Formatting Charts
self.fig = Figure(figsize=(5, 1), dpi=100)
self.axis = self.fig.add_subplot(111)
self.fig.patch.set_facecolor("None")
self.axis.patch.set_visible(False)
self.axis.spines['top'].set_visible(False)
self.axis.spines['right'].set_visible(False)
self.axis.spines['bottom'].set_visible(False)
self.axis.spines['left'].set_visible(False)
self.axis.get_xaxis().set_ticks([])
self.axis.tick_params(axis='y', colors='white')
self.canvas = FigureCanvas(self.fig)
self.canvas.set_size_request(500, 100)
self.canvas.mpl_connect('motion_notify_event', self.hover)
self.canvas.mpl_connect('axes_leave_event', self.hide_label)
self.chart.pack_start(self.label, True, True, 0)
self.chart.pack_start(self.canvas, True, True, 0)
self.view.pack_start(self.chart, False, False, 20)
self.view.pack_start(self.summary, False, False, 15)
self._store = DataStore()
def get_view(self) -> Gtk.Box:
"""
Returns the view object for rendering ui.
:return: View
"""
return self.view
def render(self, weather_data: list, chart_data: list):
"""
Update the GUI data.
:param weather_data: Weather data
:param chart_data: Charting data
"""
self.chart_data = chart_data
self._store.refresh_preference()
# Summary
for weather, box in zip(weather_data, self.items):
box[2].set_text(str(int(weather['temp'])) + DISPLAY_TEMP_UNITS[self._store.get_units()])
box[1].set_text(datetime.fromtimestamp(weather['ts']).strftime("%a"))
if not self.single_day_mode:
box[0].set_from_pixbuf(Icon.get_icon(weather['weather']['code']))
self.items[0][1].set_text("Yesterday" if self.single_day_mode else "Today")
# Chart
self.axis.clear()
self.axis.patch.set_visible(False)
self.axis.get_xaxis().set_ticks([])
self.axis.plot(list(range(len(chart_data))), self.chart_data, 'w-')
def hover(self, event: MouseEvent):
if event.inaxes is not self.axis:
return
x = int(event.xdata)
if x >= len(self.chart_data) or x < 0:
return
#.........这里部分代码省略.........