本文整理汇总了Python中matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo.set_size_request方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasGTK3Cairo.set_size_request方法的具体用法?Python FigureCanvasGTK3Cairo.set_size_request怎么用?Python FigureCanvasGTK3Cairo.set_size_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo
的用法示例。
在下文中一共展示了FigureCanvasGTK3Cairo.set_size_request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
def draw(self):
x = [5,8,10]
y = [12,16,6]
x2 = [6,9,11]
y2 = [6,15,7]
fig, ax = plt.subplots()
canvas = FigureCanvas(fig)
canvas.set_size_request(600,600)
canvas.set_parent(self._scrolledwindow)
#self._scrolledwindow.add_with_viewport(canvas)
ax.bar(x, y, align='center')
ax.bar(x2, y2, color='y', align='center')
ax.plot()
plt.title('Epic Info')
plt.ylabel('Y axis')
plt.xlabel('X axis')
#print(dir(fig.canvas))
#plt.draw()
plt.show(block=False)
示例2: __init__
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
def __init__(self, application):
""" Create a summary page containing various statistics such as the number of logs in the logbook, the logbook's modification date, etc.
:arg application: The PyQSO application containing the main Gtk window, etc.
"""
self.application = application
self.logbook = self.application.logbook
self.builder = self.application.builder
glade_file_path = join(realpath(dirname(__file__)), "res", "pyqso.glade")
self.builder.add_objects_from_file(glade_file_path, ("summary_page",))
self.summary_page = self.builder.get_object("summary_page")
self.items = {}
# Database name in large font at the top of the summary page
self.builder.get_object("database_name").set_markup("<span size=\"x-large\">%s</span>" % basename(self.logbook.path))
self.items["LOG_COUNT"] = self.builder.get_object("log_count")
self.items["QSO_COUNT"] = self.builder.get_object("qso_count")
self.items["DATE_MODIFIED"] = self.builder.get_object("date_modified")
# Yearly statistics
config = configparser.ConfigParser()
have_config = (config.read(expanduser('~/.config/pyqso/preferences.ini')) != [])
(section, option) = ("general", "show_yearly_statistics")
if(have_config and config.has_option(section, option)):
if(config.getboolean("general", "show_yearly_statistics") and have_matplotlib):
hbox = Gtk.HBox()
label = Gtk.Label(label="Display statistics for year: ", halign=Gtk.Align.START)
hbox.pack_start(label, False, False, 6)
year_select = Gtk.ComboBoxText()
min_year, max_year = self.get_year_bounds()
if min_year and max_year:
for year in range(max_year, min_year-1, -1):
year_select.append_text(str(year))
year_select.append_text("")
year_select.connect("changed", self.on_year_changed)
hbox.pack_start(year_select, False, False, 6)
self.summary_page.pack_start(hbox, False, False, 4)
self.items["YEARLY_STATISTICS"] = Figure()
canvas = FigureCanvas(self.items["YEARLY_STATISTICS"])
canvas.set_size_request(800, 175)
canvas.show()
self.summary_page.pack_start(canvas, True, True, 0)
# Summary tab label and icon.
tab = Gtk.HBox(homogeneous=False, spacing=0)
label = Gtk.Label(label="Summary ")
icon = Gtk.Image.new_from_icon_name(Gtk.STOCK_INDEX, Gtk.IconSize.MENU)
tab.pack_start(label, False, False, 0)
tab.pack_start(icon, False, False, 0)
tab.show_all()
self.logbook.notebook.insert_page(self.summary_page, tab, 0) # Append as a new tab
self.logbook.notebook.show_all()
return
示例3: open_detatiled_station_window
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
def open_detatiled_station_window(self, station_name, x=0, y=0):
latest_data = []
station_url = ""
#Find the correct link for the requested station
for link in self.every_station_link:
if link[0] == station_name:
#Perform detailed scrape
latest_data = detailed_station_scrape(link[1], station_name)
station_url = link[1]
csv_url = get_csv_link(station_url, station_name)
# Build new window based on Glade file.
builder = Gtk.Builder()
builder.add_from_file("Station Window.glade")
builder.connect_signals(Handler())
builder.get_object("label1").set_text(station_name)
builder.get_object("label7").set_text(latest_data[0])
builder.get_object("label8").set_text(latest_data[1])
builder.get_object("label9").set_text(latest_data[2])
builder.get_object("label10").set_text(latest_data[3])
builder.get_object("label11").set_text(latest_data[4])
builder.get_object("label18").set_text(latest_data[5])
builder.get_object("label19").set_text(latest_data[6])
builder.get_object("label20").set_text(latest_data[7])
builder.get_object("label21").set_text(latest_data[8])
builder.get_object("label22").set_text(latest_data[9])
builder.get_object("label26").set_text(latest_data[10])
builder.get_object("label27").set_text(latest_data[11])
builder.get_object("label28").set_text(latest_data[12])
display_station_win = builder.get_object("window1")
display_station_win.set_title(station_name)
display_station_win.move(x,y)
refresh_butt = builder.get_object("button1")
refresh_butt.connect("clicked", self.on_refresh_clicked)
display_station_win.connect("delete-event", self.close_window_and_remove_reference)
self.list_of_current_windows.append(display_station_win)#Dogfood # Stores current window in array so they can be iterated through when saving
# Graph
if csv_url != "no data":
temperature_data = csv_scrap(csv_url)
fig = temperature_graph(temperature_data)
scroll_win = builder.get_object("scrolledwindow1")
canvas = FigureCanvas(fig)
canvas.set_size_request(400,400)
scroll_win.add_with_viewport(canvas)
display_station_win.show_all()
示例4: PlotWidget
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
class PlotWidget(Widgets.WidgetBase):
def __init__(self, plot, width=500, height=500):
super(PlotWidget, self).__init__()
self.widget = FigureCanvas(plot.get_figure())
self.plot = plot
self.widget.set_size_request(width, height)
self.widget.show_all()
def configure_window(self, wd, ht):
self.logger.debug("canvas resized to %dx%d" % (wd, ht))
fig = self.plot.get_figure()
fig.set_size_inches(float(wd) / fig.dpi, float(ht) / fig.dpi)
示例5: create_ui
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
def create_ui(self):
self.fig = Figure(figsize=(8, 8), dpi=100)
self.axes = []
sw = Gtk.ScrolledWindow()
plot_box = Gtk.VBox()
sw.add_with_viewport(plot_box)
canvas = FigureCanvas(self.fig)
canvas.set_size_request(500, 600)
plot_box.pack_start(canvas, True, True, 0)
toolbar = NavigationToolbar2(canvas, sw)
self.widget.pack_start(toolbar, False, False, 0)
self.widget.add(sw)
示例6: onGoPressed
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
def onGoPressed(self, button):
symbol = self.symbol.get_text()
asset = pd.io.data.DataReader(symbol, 'yahoo')
figure = Figure(figsize=(5, 4), dpi=100, frameon=False)
subplot = figure.add_subplot(1, 1, 1)
subplot.plot(asset.index, asset['Adj Close'])
subplot.autoscale_view(True, True, True)
canvas = FigureCanvas(figure)
canvas.set_size_request(500, 250)
sw = self.app.builder.get_object('scrolledwindow1')
# remove old children
for child in sw.get_children():
sw.remove(child)
sw.add(canvas)
sw.show_all()
示例7: Profile
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
class Profile(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Profile")
#f = Figure(figsize=(5,4), dpi=100)
f = Figure()
self.axes = f.add_subplot(111)
self.axes.set_xlabel('Time (sec.)')
self.axes.set_ylabel('Temperature (C)')
self.axes.set_xlim(0, 5*60)
self.axes.set_ylim(20, 300)
self.axes.grid()
self.axes.xaxis.set_major_formatter(FuncFormatter(self.format_xaxis))
self.x = []
self.y = []
self.plot, = self.axes.plot(self.x, self.y, 'o-', picker=5)
self.minutes = False
self.file_name = None
self.canvas = FigureCanvas(f)
self.canvas.set_size_request(800,600)
self.canvas.mpl_connect('button_press_event', self.onclick)
self.canvas.mpl_connect('button_release_event', self.onrelease)
self.canvas.mpl_connect('pick_event', self.onpick)
self.canvas.mpl_connect('motion_notify_event', self.onmotion)
self.picking = None
self.store = Gtk.ListStore(str, str)
self.tree = Gtk.TreeView(self.store)
renderer = Gtk.CellRendererText()
renderer.set_property("editable", True)
renderer.connect('edited', self.on_time_edited)
column = Gtk.TreeViewColumn("Time", renderer, text=0)
self.tree.append_column(column)
renderer = Gtk.CellRendererText()
renderer.set_property("editable", True)
renderer.connect('edited', self.on_temp_edited)
column = Gtk.TreeViewColumn("Temperature", renderer, text=1)
self.tree.append_column(column)
self.box = Gtk.Box()
self.box.pack_start(self.canvas, False, False, 0)
self.box.pack_start(self.tree, True, True, 0)
action_group = Gtk.ActionGroup("profile_actions")
action_group.add_actions([
("FileMenu", None, "File", None, None, None),
("FileNew", Gtk.STOCK_NEW, "_New", "<control>N", None, self.on_file_new),
("FileOpen", Gtk.STOCK_OPEN, "_Open", "<control>O", None, self.on_file_open),
("FileSave", Gtk.STOCK_SAVE, "_Save", "<control>S", None, self.on_file_save),
("FileSaveAs", Gtk.STOCK_SAVE_AS, "Save _As…", "<shift><control>S", None, self.on_file_save_as),
("FileQuit", Gtk.STOCK_QUIT, "_Quit", "<control>Q", None, Gtk.main_quit)
])
uimanager = Gtk.UIManager()
uimanager.add_ui_from_string(UI_INFO)
accelgroup = uimanager.get_accel_group()
self.add_accel_group(accelgroup)
uimanager.insert_action_group(action_group)
menubar = uimanager.get_widget("/MenuBar")
self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.vbox.pack_start(menubar, False, False, 0)
self.vbox.pack_start(self.box, True, True, 0)
self.statusbar = Gtk.Statusbar()
self.status_pos = self.statusbar.get_context_id("position")
self.vbox.pack_start(self.statusbar, False, False, 0)
self.add(self.vbox)
def open_file(self, name):
reader = csv.reader(open(name, 'rb'))
x, y = zip(*reader)
x = [ float(i) for i in x]
y = [ float(i) for i in y]
self.x, self.y = x, y
self.file_name = name
self.set_title('Profile - ' + name)
self.update_data()
self.update_scale()
self.canvas.draw()
def save_file(self, name):
writer = csv.writer(open(name, 'wd'))
writer.writerows(zip(self.x, self.y))
self.file_name = name
self.set_title('Profile - ' + name)
def on_file_new(self, widget):
self.file_name = None
self.set_title('Profile')
self.x = []
self.y = []
self.store.clear()
self.update_data()
self.update_scale()
self.canvas.draw()
def on_file_open(self, widget):
#.........这里部分代码省略.........
示例8: ODEGui
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
class ODEGui(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="ODE Solver")
#Main Box
self.grid = Gtk.Grid(column_spacing=6)
#Dopdown for kind of solver
self.combo_solver = Gtk.ComboBoxText()
self.combo_solver.set_entry_text_column(0)
self.solvers = ["Euler explicit", "Heun explicit", "Runge-Kutta explicit","Midpoint implicit","Heun implicit"]
for solver in self.solvers:
self.combo_solver.append_text(solver)
self.combo_solver.set_active(0)
#Entrys
self.function_entry = Gtk.Entry(text="test")
self.x0_entry = Gtk.Entry(text="1,2")
self.t0_entry = Gtk.Entry(text="0")
self.T_entry = Gtk.Entry(text="5")
self.N_entry = Gtk.Entry(text="100")
self.eps_entry = Gtk.Entry(text="0.1")
#Labels
self.function_label = Gtk.Label("Function Name:")
self.x0_label = Gtk.Label("Starting Point:")
self.t0_label = Gtk.Label("Starting Time:")
self.T_label = Gtk.Label("Ending Time:")
self.N_label = Gtk.Label("Number of Steps:")
self.eps_label = Gtk.Label("Stopping Criterium:")
#Buttons
self.plot_button = Gtk.Button(label="Plot")
self.reset_plot_button = Gtk.Button(label="Reset Plot")
self.plot_button.connect("clicked",self.on_plot_clicked)
self.reset_plot_button.connect("clicked",self.reset)
#Box on right side
self.boxRight = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
#Plot
self.fig = Figure(figsize=(5,4), dpi=100)
self.ax = self.fig.add_subplot(111)
self.ax.plot()
self.canvas = FigureCanvas(self.fig)
self.canvas.set_size_request(400,400)
self.sw = Gtk.ScrolledWindow()
self.sw.add_with_viewport(self.canvas)
self.sw.set_min_content_width(500)
self.sw.set_min_content_height(500)
self.boxRight.pack_start(self.sw,True,True,0)
self.toolbar = NavigationToolbar(self.canvas,self)
self.boxRight.pack_start(self.toolbar,False,True,0)
self.foo = Gtk.Label("")
#Left Side
self.gridLeft = Gtk.Grid(row_spacing=6)
#Put it together
self.gridLeft.attach(self.combo_solver,0,0,1,1)
self.gridLeft.attach(self.foo,0,1,1,1)
self.gridLeft.attach(self.function_label,0,2,1,1)
self.gridLeft.attach(self.function_entry,0,3,1,1)
self.gridLeft.attach(self.x0_label,0,4,1,1)
self.gridLeft.attach(self.x0_entry,0,5,1,1)
self.gridLeft.attach(self.t0_label,0,6,1,1)
self.gridLeft.attach(self.t0_entry,0,7,1,1)
self.gridLeft.attach(self.T_label,0,8,1,1)
self.gridLeft.attach(self.T_entry,0,9,1,1)
self.gridLeft.attach(self.N_label,0,10,1,1)
self.gridLeft.attach(self.N_entry,0,11,1,1)
self.gridLeft.attach(self.eps_label,0,12,1,1)
self.gridLeft.attach(self.eps_entry,0,13,1,1)
self.gridLeft.attach(self.plot_button,0,14,1,1)
self.gridLeft.attach(self.reset_plot_button,0,15,1,1)
# self.boxLeft.pack_start(self.function_entry,True,True,0)
# self.boxLeft.pack_start(self.x0_entry,True,True,0)
# self.boxLeft.pack_start(self.t0_entry,True,True,0)
# self.boxLeft.pack_start(self.T_entry,True,True,0)
# self.boxLeft.pack_start(self.N_entry,True,True,0)
# self.boxLeft.pack_start(self.eps_entry,True,True,0)
# self.boxLeft.pack_start(self.plot_button,True,True,0)
# self.boxLeft.pack_start(self.reset_plot_button,True,True,0)
self.grid.attach(self.gridLeft,0,0,2,6)
self.grid.attach(self.boxRight,2,0,4,6)
#.........这里部分代码省略.........
示例9: Figure
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
#MATPLOTLIB ANIMATION
#plotwindow = Gtk.Window()
#plotwindow.set_default_size(400, 400)
fig1 = Figure(figsize=(5,5), dpi=100)
ax1 = fig1.add_subplot(111)
ax1.set_xlim(0, 300)
ax1.set_ylim(0, g.num_vertices() )
ax1.set_xlabel('time')
ax1.set_title('SIR Time Plot')
#sw = Gtk.ScrolledWindow()
#plotwindow.add(sw)
canvas = FigureCanvas(fig1)
canvas.set_size_request(400,400)
#sw.add_with_viewport(canvas)
else:
count = 0
win = Gtk.OffscreenWindow()
win.set_default_size(1000, 700)
win.graph = GraphWidget(g, pos,
edge_color=[0.6, 0.6, 0.6, 1],
vertex_fill_color=state,
vertex_halo=newly_infected,
vertex_halo_color=[0.8, 0, 0, 0.6])
win.add(win.graph)
# This function will be called repeatedly by the GTK+ main loop, and we use it
示例10: MonitorWindow
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
class MonitorWindow(Gtk.Window):
def __init__(self, pid):
Gtk.Window.__init__(self, title="Monitor")
self.pid = pid
self.restart = False
main_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
f = matplotlib.figure.Figure()
self.axes = f.add_subplot(111)
self.axes.set_xlabel('Time (sec.)')
self.axes.set_ylabel('Temperature (C)')
self.axes.autoscale()
self.out_axes = self.axes.twinx()
self.out_axes.set_ylabel('OUT (%)')
self.out_axes.autoscale()
self.axes.grid()
self.pv_x = []
self.pv_y = []
self.sv_x = []
self.sv_y = []
self.out_x = []
self.out_y = []
self.pv_plot, = self.axes.plot(self.pv_x, self.pv_y, 'b--') #b
self.sv_plot, = self.axes.plot(self.sv_x, self.sv_y, 'k-') #k
self.out_plot, = self.out_axes.plot(self.out_x, self.out_y, 'r:') #r
self.canvas = FigureCanvas(f)
self.canvas.set_size_request(800,600)
vbox.add(self.canvas)
hbox = Gtk.Box()
# Start/restart program
button = Gtk.Button('First Step')
button.connect('clicked', self.on_restart)
hbox.pack_start(button, False, False, 0)
button = Gtk.Button('Continue')
button.connect('clicked', lambda x: self.pid.coil('next'))
hbox.pack_start(button, False, False, 0)
button = Gtk.Button('Pause')
button.connect('clicked', lambda x: self.pid.coil('pause'))
hbox.pack_start(button, False, False, 0)
button = Gtk.Button('Last Step')
button.connect('clicked', lambda x: self.pid.coil('end'))
hbox.pack_start(button, False, False, 0)
hbox.set_sensitive(False)
vbox.add(hbox)
main_hbox.add(vbox)
# Extra information required
# Manual/automatic
# Program step
# Program status (running/pause)
# Time/time remaining in step
# PV/SV/dSV display?
# AL1/AL2
self.add(main_hbox)
table = Gtk.Table()
row = 0
combo = widgets.PIDComboBoxText(pid, 'ModL')
pid.connect('changed', lambda pid, n, val, mult, w=combo: w.set_sensitive(not val['A/M']) if n == 'flags' else None)
label = Gtk.Label('Mode')
label.set_alignment(0, 0.5)
table.attach(label, 0, 1, row, row+1, yoptions=Gtk.AttachOptions.SHRINK)
table.attach(combo, 1, 2, row, row+1, yoptions=Gtk.AttachOptions.SHRINK)
row += 1
# Allow changing SV in manual mode
# FIXME: disable if not SV?
spin = widgets.PIDSpinButton(pid, 'SV')
spin.set_sensitive(False)
#combo.connect('changed', lambda combo, s=spin, c=combo: s.set_sensitive(c.get_active_text() == 'SV'))
pid.connect('changed', lambda pid, n, val, mult, w=spin, c=combo: w.set_sensitive(not val['A/M'] and c.get_active_text() == 'SV') if n == 'flags' else None)
pid.connect('changed', lambda pid, n, val, mult, w=spin: w.set_sensitive(val == 'SV') if n == 'ModL' else None)
pid.connect('changed', lambda pid, n, val, mult, w=hbox: w.set_sensitive(val != 'SV') if n == 'ModL' else None)
label = Gtk.Label('Set value')
label.set_alignment(0, 0.5)
table.attach(label, 0, 1, row, row+1, yoptions=Gtk.AttachOptions.SHRINK)
table.attach(spin, 1, 2, row, row+1, yoptions=Gtk.AttachOptions.SHRINK)
row += 1
label = Gtk.Label('Dynamic SV')
label.set_alignment(0, 0.5)
table.attach(label, 0, 1, row, row+1, yoptions=Gtk.AttachOptions.SHRINK)
label = Gtk.Label()
label.set_alignment(0, 0.5)
table.attach(label, 1, 2, row, row+1, yoptions=Gtk.AttachOptions.SHRINK)
pid.connect('changed', lambda pid, n, val, mult, w=label: w.set_text('%0.1f'%val if mult == .1 else '%d'%val) if n == 'dSV' else None)
#.........这里部分代码省略.........
示例11: __init__
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
#.........这里部分代码省略.........
label = Gtk.Label("Colormap", halign=Gtk.Align.START)
box.pack_start(label, True, True, 0)
cmapstore = Gtk.ListStore(str, GdkPixbuf.Pixbuf)
cmaps = sorted(pl.cm.datad)
for item in cmaps:
cmapstore.append([item, None])
self.cmapcombo = Gtk.ComboBox.new_with_model(cmapstore)
self.cmapcombo.connect("changed", self.on_cmapcombo_changed)
self.cmapcombo.set_active(0)
renderer = Gtk.CellRendererText()
self.cmapcombo.pack_start(renderer, True)
self.cmapcombo.add_attribute(renderer, "text", 0)
renderer = Gtk.CellRendererPixbuf()
self.cmapcombo.pack_start(renderer, False)
self.cmapcombo.add_attribute(renderer, "pixbuf", 1)
box.pack_start(self.cmapcombo, True, True, 0)
def setup_image_box(self):
xx = self.xsize / float(self.dpi) # inches
yy = self.ysize / float(self.dpi) # inches
# TODO: make it resizable
self.fig = Figure(figsize=(xx, yy), dpi=self.dpi)
self.canvas = FigureCanvas(self.fig) # a gtk.DrawingArea
# setup drawing canvas
self.canvas.set_size_request(self.xsize, self.ysize)
self.canvas.connect('button-press-event' , self.on_canvas_button_press)
self.canvas.connect('button-release-event', self.on_canvas_button_release)
self.canvas.connect('motion-notify-event' , self.on_canvas_motion_notify)
self.image_box.add(self.canvas)
def create_labeled_entry(self, name, parent, orientation='horizontal', spacing=10, xpad=0):
box = Gtk.Box(orientation=orientation, spacing=spacing)
parent.pack_start(box, True, True, 0)
label = Gtk.Label(label=name, halign=Gtk.Align.START, xpad=xpad)
box.pack_start(label, True, False, 0)
entry = Gtk.Entry(name=name)
box.pack_start(entry, True, True, 0)
return entry
def set_entry_value(self, entry):
name = entry.get_name()
value = getattr(self, name)
if int(value) == value:
value_str = "{0}".format(value)
else:
value_str = "{0:.{1}f}".format(value, self.digits).rstrip("0")
entry.set_text(value_str)
示例12: CampaignGraph
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
class CampaignGraph(object):
"""
A basic graph provider for using :py:mod:`matplotlib` to create graph
representations of campaign data. This class is meant to be subclassed
by real providers.
"""
name = 'Unknown'
"""The name of the graph provider."""
name_human = 'Unknown'
"""The human readable name of the graph provider used for UI identification."""
graph_title = 'Unknown'
"""The title that will be given to the graph."""
table_subscriptions = []
"""A list of tables from which information is needed to produce the graph."""
is_available = True
def __init__(self, config, parent, size_request=None):
"""
:param dict config: The King Phisher client configuration.
:param parent: The parent window for this object.
:type parent: :py:class:`Gtk.Window`
:param tuple size_request: The size to set for the canvas.
"""
self.config = config
"""A reference to the King Phisher client configuration."""
self.parent = parent
"""The parent :py:class:`Gtk.Window` instance."""
self.figure, _ = 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.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._menu_item_show_toolbar = menu_item
self.popup_menu.append(menu_item)
self.popup_menu.show_all()
self.navigation_toolbar.hide()
def _load_graph(self, info_cache):
raise NotImplementedError()
def _graph_bar_set_yparams(self, top_lim):
min_value = top_lim + (top_lim * 0.075)
if min_value <= 25:
scale = 5
else:
scale = scale = 10 ** (len(str(int(min_value))) - 1)
inc_scale = scale
while scale <= min_value:
scale += inc_scale
top_lim = scale
ax = self.axes[0]
yticks = set((round(top_lim * 0.5), top_lim))
ax.set_yticks(tuple(yticks))
ax.set_ylim(top=top_lim)
return
def _graph_null_pie(self, title):
ax = self.axes[0]
ax.pie((100,), labels=(title,), colors=(MPL_COLOR_NULL,), autopct='%1.0f%%', shadow=True, startangle=90)
ax.axis('equal')
return
def add_legend_patch(self, legend_rows, fontsize=None):
handles = []
if not fontsize:
scale = self.markersize_scale
if scale < 5:
fontsize = 'xx-small'
elif scale < 7:
fontsize = 'x-small'
elif scale < 9:
fontsize = 'small'
else:
fontsize = 'medium'
for row in legend_rows:
handles.append(patches.Patch(color=row[0], label=row[1]))
self.axes[0].legend(handles=handles, fontsize=fontsize, loc='lower right')
def graph_bar(self, bars, color=None, xticklabels=None, ylabel=None):
"""
Create a standard bar graph with better defaults for the standard use
cases.
:param list bars: The values of the bars to graph.
#.........这里部分代码省略.........
示例13: CampaignGraph
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
class CampaignGraph(object):
"""
A basic graph provider for using :py:mod:`matplotlib` to create graph
representations of campaign data. This class is meant to be subclassed
by real providers.
"""
name = 'Unknown'
"""The name of the graph provider."""
name_human = 'Unknown'
"""The human readable name of the graph provider used for UI identification."""
graph_title = 'Unknown'
"""The title that will be given to the graph."""
table_subscriptions = []
"""A list of tables from which information is needed to produce the graph."""
is_available = True
def __init__(self, application, size_request=None, style_context=None):
"""
:param tuple size_request: The size to set for the canvas.
"""
self.application = application
self.style_context = style_context
self.config = application.config
"""A reference to the King Phisher client configuration."""
self.figure, _ = pyplot.subplots()
self.figure.set_facecolor(self.get_color('bg', ColorHexCode.WHITE))
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.application.get_active_window())
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._menu_item_show_toolbar = menu_item
self.popup_menu.append(menu_item)
self.popup_menu.show_all()
self.navigation_toolbar.hide()
self._legend = None
@property
def rpc(self):
return self.application.rpc
@staticmethod
def _ax_hide_ticks(ax):
for tick in ax.yaxis.get_major_ticks():
tick.tick1On = False
tick.tick2On = False
@staticmethod
def _ax_set_spine_color(ax, spine_color):
for pos in ('top', 'right', 'bottom', 'left'):
ax.spines[pos].set_color(spine_color)
def _load_graph(self, info_cache):
raise NotImplementedError()
def add_legend_patch(self, legend_rows, fontsize=None):
if self._legend is not None:
self._legend.remove()
self._legend = None
if fontsize is None:
scale = self.markersize_scale
if scale < 5:
fontsize = 'xx-small'
elif scale < 7:
fontsize = 'x-small'
elif scale < 9:
fontsize = 'small'
else:
fontsize = 'medium'
legend_bbox = self.figure.legend(
tuple(patches.Patch(color=patch_color) for patch_color, _ in legend_rows),
tuple(label for _, label in legend_rows),
borderaxespad=1.25,
fontsize=fontsize,
frameon=True,
handlelength=1.5,
handletextpad=0.75,
labelspacing=0.3,
loc='lower right'
)
legend_bbox.legendPatch.set_linewidth(0)
self._legend = legend_bbox
def get_color(self, color_name, default):
"""
Get a color by its style name such as 'fg' for foreground. If the
#.........这里部分代码省略.........
示例14: __init__
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
class Handler:
def __init__(self):
global ppp
self.window1 = builder.get_object("window1")
self.window1.set_title("SPCinspector - No file loaded")
self.vbox1 = builder.get_object("vbox1")
self.label0 = builder.get_object("label0")
self.label1 = builder.get_object("label1")
self.label2 = builder.get_object("label2")
self.label3 = builder.get_object("label3")
self.label4 = builder.get_object("label4")
self.label5 = builder.get_object("label5")
self.label6 = builder.get_object("label6")
self.label7 = builder.get_object("label7")
self.label8 = builder.get_object("label8")
# self.label9 = builder.get_object("label9")
# self.label10 = builder.get_object("label10")
# self.label11 = builder.get_object("label11")
self.label12 = builder.get_object("label12")
self.label13 = builder.get_object("label13")
self.label14 = builder.get_object("label14")
self.label15 = builder.get_object("label15")
self.label16 = builder.get_object("label16")
self.label17 = builder.get_object("label17")
self.label18 = builder.get_object("label18")
self.label19 = builder.get_object("label19")
self.label20 = builder.get_object("label20")
self.label21 = builder.get_object("label21")
self.label22 = builder.get_object("label22")
self.label23 = builder.get_object("label23")
self.label24 = builder.get_object("label24")
self.label25 = builder.get_object("label25")
self.label26 = builder.get_object("label26")
self.spin1 = builder.get_object("spin1") # depth
self.spin2 = builder.get_object("spin2") # species
self.spin3 = builder.get_object("spin3") # E-bins
self.spin1.set_sensitive(False)
self.spin2.set_sensitive(False)
self.spin3.set_sensitive(False)
self.button1 = builder.get_object("button1")
self.button2 = builder.get_object("button2")
self.button1.set_sensitive(False)
self.cur_depth = 0
self.cur_species = 0
self.cur_ebin = 0
self.spc = []
self.path = ""
fig = Figure(figsize=(5,5), dpi=100)
#ax = fig.add_subplot(111, projection='polar')
self.ax = fig.add_subplot(111)
#x = [1, 2, 3, 4, 5]
#y = [1, 4, 9, 16, 25]
#self.ax.plot(x,y)
self.ax.set_xlabel('Energy [MeV/u]')
self.ax.set_ylabel('Histories')
#sw = Gtk.ScrolledWindow()
#myfirstwindow.add(sw)
self.canvas = FigureCanvas(fig)
self.canvas.set_size_request(600,600)
self.vbox1.pack_end(self.canvas,True,True,True)
self.zlut = {
1:'H',2:'He',
3:'Li',4:'Be',5:'B',6:'C',7:'N', 8:'O',9:'F',10:'Ne',
11:'Na',12:'Mg',13:'Al',14:'Si',15:'P',16:'S',17:'Cl',18:'Ar',
19:'K',20:'Ca'
}
print(ppp)
if os.path.isfile(ppp):
self.load_spc(ppp)
def update_plot(self):
d = self.spc.data[self.cur_depth]
ds = d.species[self.cur_species]
dse = ds.ebindata
dsh = ds.histdata
dsc = ds.rcumdata
#print("NB:",len(dse),len(dsh),len(dsc))
self.ax.cla()
#.........这里部分代码省略.........
示例15: GraphBase
# 需要导入模块: from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo [as 别名]
# 或者: from matplotlib.backends.backend_gtk3cairo.FigureCanvasGTK3Cairo import set_size_request [as 别名]
#.........这里部分代码省略.........
tuple(label for _, label in legend_rows),
borderaxespad=1.25,
fontsize=fontsize,
frameon=True,
handlelength=1.5,
handletextpad=0.75,
labelspacing=0.3,
loc='lower right'
)
legend_bbox.legendPatch.set_linewidth(0)
self._legend = legend_bbox
def get_color(self, color_name, default):
"""
Get a color by its style name such as 'fg' for foreground. If the
specified color does not exist, default will be returned. The underlying
logic for this function is provided by
:py:func:`~.gui_utilities.gtk_style_context_get_color`.
:param str color_name: The style name of the color.
:param default: The default color to return if the specified one was not found.
:return: The desired color if it was found.
:rtype: tuple
"""
color_name = 'theme_color_graph_' + color_name
sc_color = gui_utilities.gtk_style_context_get_color(self.style_context, color_name, default)
return (sc_color.red, sc_color.green, sc_color.blue)
def make_window(self):
"""
Create a window from the figure manager.
:return: The graph in a new, dedicated window.
:rtype: :py:class:`Gtk.Window`
"""
if self.manager is None:
self.manager = FigureManager(self.canvas, 0)
self.navigation_toolbar.destroy()
self.navigation_toolbar = self.manager.toolbar
self._menu_item_show_toolbar.set_active(True)
window = self.manager.window
window.set_transient_for(self.application.get_active_window())
window.set_title(self.graph_title)
return window
@property
def fontsize_scale(self):
scale = self.markersize_scale
if scale < 5:
fontsize = 'xx-small'
elif scale < 7:
fontsize = 'x-small'
elif scale < 9:
fontsize = 'small'
else:
fontsize = 'medium'
return fontsize
@property
def markersize_scale(self):
bbox = self.axes[0].get_window_extent().transformed(self.figure.dpi_scale_trans.inverted())
return bbox.width * self.figure.dpi * 0.01
def mpl_signal_canvas_button_pressed(self, event):
if event.button != 3:
return
self.popup_menu.menu.popup(None, None, None, None, event.button, Gtk.get_current_event_time())
return True
def signal_activate_popup_menu_export(self, action):
dialog = extras.FileChooserDialog('Export Graph', self.application.get_active_window())
file_name = self.config['campaign_name'] + '.png'
response = dialog.run_quick_save(file_name)
dialog.destroy()
if not response:
return
destination_file = response['target_path']
self.figure.savefig(destination_file, dpi=200, facecolor=self.figure.get_facecolor(), format='png')
def signal_activate_popup_refresh(self, event):
self.refresh()
def signal_toggled_popup_menu_show_toolbar(self, widget):
if widget.get_property('active'):
self.navigation_toolbar.show()
else:
self.navigation_toolbar.hide()
def resize(self, width=0, height=0):
"""
Attempt to resize the canvas. Regardless of the parameters the canvas
will never be resized to be smaller than :py:attr:`.minimum_size`.
:param int width: The desired width of the canvas.
:param int height: The desired height of the canvas.
"""
min_width, min_height = self.minimum_size
width = max(width, min_width)
height = max(height, min_height)
self.canvas.set_size_request(width, height)