本文整理汇总了Python中matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg类的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasGTKAgg类的具体用法?Python FigureCanvasGTKAgg怎么用?Python FigureCanvasGTKAgg使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FigureCanvasGTKAgg类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class Display:
""" This class is responsible for rendering the graph in the upper portion
of the window. The data in the graph is taken from a Simulation object,
which is accessed through the main Interface object. """
# This is a color I chose to perfectly match the background of the rest of
# the interface. It might only work on my computer.
# Malingo: Yes, it only works on your computer. It depends on what gtk
# theme the user has chosen.
background = "#edecea"
def __init__(self, main):
self.main = main
pi = numpy.pi
self.abscissa = numpy.arange(-pi - .25, pi + 0.25, 0.01)
self.curve = None
self.canvas = None
def setup(self, layout):
""" This method creates the graph that is displayed on the top half of
the user interface. Currently, the axes are completely hard-coded in
this method and cannot be changed on-the-fly. """
figure = Figure(facecolor=Display.background)
axes = figure.add_subplot(111)
# In order to create a line object, a dummy line needs to be plotted.
# This line will get replaced before the GUI is shown to the user.
pi = numpy.pi
x = y = self.abscissa
self.curve = axes.plot(x, y)[0]
self.canvas = FigureCanvasGTKAgg(figure)
# The tick labels are formatted using LaTeX. This makes it possible
# to use symbols like pi.
axes.set_xticks((-pi, 0, pi))
axes.set_xticklabels((r"-\pi", "0", r"\pi"))
axes.set_xlim(-pi - 0.25, pi + 0.25)
axes.set_yticks((0, 1))
axes.set_yticklabels(("0", "1"))
axes.set_ylim((-0.1, 1.1))
layout.pack_start(self.canvas)
def update(self):
""" This method updates the graph using the new ordinate values
returned by the simulation. """
main = self.main
simulation = main.simulation
ordinate = simulation.plot(self.abscissa)
self.curve.set_ydata(ordinate)
self.canvas.draw()
示例2: drawMonitorTest
def drawMonitorTest(self):
try:
self.builder.get_object("tmcspace").remove(self.canvastmc)
self.axistmc.clear()
except:
pass
#Add cropping
self.axistmc.imshow(self.tmonimage, cmap=cm.gray) #set scale to 0,255 somehow
#Maybe this needn't be redefined for every draw - only need draw() but not drawn often anyway
self.canvastmc=FigureCanvasGTKAgg(self.figuretmc)
self.canvastmc.draw()
self.canvastmc.show()
self.builder.get_object("tmcspace").pack_start(self.canvastmc, True, True)
for i in range(len(self.trlist)):
for cont in self.contours:
#if self.rlist[i]==cont.ritem:
#TODO remove hidden parameters here
if np.abs(self.trlist[i][0][0]-cont.ritem[0][0])<=4 and np.abs(self.trlist[i][0][1]-cont.ritem[0][1])<=4:
item=self.trlist[i]
r=Rectangle(item[0], item[1], item[2], fill=False, color="blue")
self.axistmc.add_patch(r)
#could add width, height check as well
#Always draw saved contours in blue
for ditem in self.contours:
item=ditem.ritem
示例3: openCameraConfig
def openCameraConfig(self):
try:
self.builder.get_object("ccimgbox").remove(self.canvascc)
except:
pass
ret,img = self.cap.read()
try:
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#cv2.imshow("newtest",img)
except:
img=np.zeros((100,100))
self.builder.get_object("resx").set_text(str(img.shape[1]))
self.builder.get_object("resy").set_text(str(img.shape[0]))
self.resolution=(img.shape[1], img.shape[0])
if img.shape[1]<self.screensize[0] and img.shape[0]<self.screensize[1]:
pass
else:
img=imresize(img, (img.shape[0]/2, img.shape[1]/2))
self.axiscc.imshow(img, cmap=cm.gray) #set scale to 0,255 somehow
self.canvascc=FigureCanvasGTKAgg(self.figurecc)
self.canvascc.draw()
self.canvascc.show()
self.builder.get_object("ccimgbox").pack_start(self.canvascc, True, True)
self.builder.get_object("cameraconfig").set_visible(1)
示例4: __init__
def __init__(self, dpi=100, x_pixel_size=500, y_pixel_size=400):
gtk.HBox.__init__(self)
# If the class is being reinitialized, we need to remove the old plot
[self.remove(child) for child in self.get_children()]
self.vbox = gtk.VBox()
self.pack_start(self.vbox)
# this is bad with labels, I have to figure out why
self.connect('size_allocate', self._full_update)
self.fig = Figure(figsize=(float(x_pixel_size)/dpi,
float(y_pixel_size)/dpi),
dpi=dpi)
self.fig.set_facecolor('white')
self.canvas = FigureCanvasGTKAgg(self.fig)
self.ax = self.fig.add_subplot(111)
self.vbox.pack_end(self.canvas)
self.canvas.connect('button_press_event', self._on_mouse_click)
self.first_update = True
self.settings = {}
self.n_lines = None
#self.line_styles = None
#self.line_colors = None
self.lines = None
self.saved_window_size = None
self.background = None
self.auto_x_scale = False
self.auto_y_scale = False
示例5: setup
def setup(self, layout):
""" This method creates the graph that is displayed on the top half of
the user interface. Currently, the axes are completely hard-coded in
this method and cannot be changed on-the-fly. """
figure = Figure(facecolor=Display.background)
axes = figure.add_subplot(111)
# In order to create a line object, a dummy line needs to be plotted.
# This line will get replaced before the GUI is shown to the user.
pi = numpy.pi
x = y = self.abscissa
self.curve = axes.plot(x, y)[0]
self.canvas = FigureCanvasGTKAgg(figure)
# The tick labels are formatted using LaTeX. This makes it possible
# to use symbols like pi.
axes.set_xticks((-pi, 0, pi))
axes.set_xticklabels((r"-\pi", "0", r"\pi"))
axes.set_xlim(-pi - 0.25, pi + 0.25)
axes.set_yticks((0, 1))
axes.set_yticklabels(("0", "1"))
axes.set_ylim((-0.1, 1.1))
layout.pack_start(self.canvas)
示例6: recreate_canvas
def recreate_canvas(self, fig):
canvas = FigureCanvas(fig)
canvas.set_size_request(450, 200)
if self.canvas_frame.get_child():
self.canvas_frame.remove(self.canvas_frame.get_child())
self.canvas_frame.add(canvas)
canvas.show()
示例7: __init__
def __init__(self):
print 'test'
self.win = gtk.Window()
#win.connect("destroy", lambda x: gtk.main_quit())
self.win.connect("delete-event", self.hideinsteadofdelete)
self.win.set_default_size(400,300)
self.win.set_title("Embedding in GTK")
f = Figure(figsize=(5,4), dpi=100)
a = f.add_subplot(111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
a.plot(t,s)
sw = gtk.ScrolledWindow()
self.win.add (sw)
# A scrolled window border goes outside the scrollbars and viewport
sw.set_border_width (10)
# policy: ALWAYS, AUTOMATIC, NEVER
sw.set_policy (hscrollbar_policy=gtk.POLICY_AUTOMATIC,
vscrollbar_policy=gtk.POLICY_ALWAYS)
canvas = FigureCanvas(f) # a gtk.DrawingArea
canvas.set_size_request(800,600)
sw.add_with_viewport (canvas)
self.win.show_all()
gtk.main()
示例8: Plotter
class Plotter(gtk.VBox):
def __init__(self, xlabel, ylabel, width=500, height=500, dpi=75):
"""
:type xlabel: str
:type ylabel: str
:type width: int
:type height: int
:type dpi: int
"""
gtk.VBox.__init__(self)
figure = Figure(figsize=(width, height), dpi=dpi)
self.axes = figure.add_subplot(111, xlabel=xlabel, ylabel=ylabel)
""" :type: matplotlib.axes.Axes """
self.axes.hold(False)
self.canvas = FigureCanvas(figure)
#self.canvas.mpl_connect('button_press_event', self.klick)
nav = NavigationToolbar(self.canvas, self)
self.pack_start(nav, False, False)
self.pack_start(self.canvas)
def leeren(self):
self.axes.hold(False)
def plot(self, x, y, **args):
self.axes.plot(x, y, antialiased=True, **args)
self.axes.hold(True)
def draw(self):
self.canvas.draw()
"""def klick(self, evt):
示例9: visualize
def visualize(*args, **kwargs):
"""
Method that does all magic to to with GTK.
All arguments passed to grapher.matplot.Graph
"""
logger.debug('Spawning a GTK window')
win = gtk.Window()
win.connect('destroy', lambda x: gtk.main_quit())
win.set_default_size(800,500)
win.set_title('BounceItBaby visualizer')
sw = gtk.ScrolledWindow()
win.add(sw)
# TODO: allow arrow/hjkl buttons to scroll
sw.set_policy(hscrollbar_policy=gtk.POLICY_ALWAYS,
vscrollbar_policy=gtk.POLICY_AUTOMATIC)
logger.debug('Building the Figure from data')
figure = Graph(*args, **kwargs)
canvas = FigureCanvas(figure)
# If time scale is 20 times longer than number of actors, make it 20 times
# wider than it is tall.
canvas.set_size_request(int(400 / figure.axes[0].get_data_ratio()), 400)
sw.add_with_viewport(canvas)
logger.debug('Displaying GTK window!')
win.show_all()
gtk.main()
示例10: __init__
def __init__(self,src,model,state):
self.src = src
self.model = model
self.__state = state
state.connect('selection-changed',self.update_spanner)
state.connect('selection-removed',self.remove_spanner)
xb = src.get_time_bounds()
yb = src.get_data_bounds()
figure = Figure(dpi=100)
self.plot = figure.add_subplot(111,xbound=xb,ybound=yb,autoscale_on=False)
self.plot.plot_date(src.get_time(True),src.get_data(True),'-')
if state.selection is None:
self.spanner = None
else:
vall,valr = state.selection
self.spanner = self.plot.axvspan(vall,valr,alpha=0.5)
self.ctx_spanners = dict()
FigureCanvas.__init__(self,figure)
self.mpl_connect('button_press_event',self.on_press)
self.mpl_connect('button_release_event',self.on_release)
self.mpl_connect('motion_notify_event',self.on_move)
model.connect('annotation-added',self.notice_annotation)
model.connect('annotation-removed',self.notice_annotation_removal)
model.connect('annotation-changed',self.notice_annotation_change)
for (id,color,boundl,boundr) in model.annotations():
self.notice_annotation(model,id,color,boundl,boundr)
示例11: __init__
class HelloMatplotlib:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("delete_event", self.delete_event)
self.window.connect("destroy", self.destroy)
self.window.set_size_request(400, 400)
self.window.set_border_width(10)
f = Figure(figsize=(5,4), dpi=100)
a = f.add_subplot(111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
a.plot(t,s)
self.canvas = FigureCanvas(f)
self.canvas.show()
self.window.add(self.canvas)
self.window.show()
def delete_event(self, widget, event, data=None):
gtk.main_quit()
def destroy(self, widget, data=None):
gtk.main_quit()
def main(self):
gtk.main()
示例12: __init__
def __init__(self, x, y, title="Graph", parent=None):
gtk.Window.__init__(self)
try:
self.set_screen(parent.get_screen())
except:
self.connect('destroy', lambda *w: self.destroy())
self.set_title(title)
self.set_default_size(800, 600)
self.set_border_width(2)
self.set_position(gtk.WIN_POS_CENTER)
box = gtk.VBox()
self.add(box)
fig = Fig(figsize=(5,4), dpi=100)
ax = fig.add_subplot(111)
ax.plot(x, y)
canvas = FigCan(fig)
canvas.mpl_connect('key_press_event', self.on_key_event)
box.pack_start(canvas)
toolbar = NavBar(canvas, self)
box.pack_start(toolbar, False, False)
self.show_all()
del box, fig, ax, canvas, toolbar
示例13: __init__
def __init__(self):
self._gladefile = "neuronview.glade"
self._builder = gtk.Builder()
self._builder.add_from_file(self._gladefile)
self._builder.connect_signals(self)
self._win = self._builder.get_object("mainwindow")
self._win.resize(900, 700)
box = self._builder.get_object("box5")
self._stimulatordictview = DictView()
self._builder.get_object("scrolledwindow2").add(self._stimulatordictview)
box = self._builder.get_object("box4")
self._neurondictview = DictView()
self._builder.get_object("scrolledwindow3").add(self._neurondictview)
self.populate_comboboxes()
self._figure = Figure(figsize=(5,4), dpi=100)
canvas = FigureCanvas(self._figure)
canvas.set_size_request(200, 250)
canvas.show()
box = self._builder.get_object("box3")
bg_style = box.get_style().bg[gtk.STATE_NORMAL]
gtk_color = (bg_style.red_float, bg_style.green_float, bg_style.blue_float)
self._figure.set_facecolor(gtk_color)
box.pack_start(canvas)
self._win.show()
gtk.main()
示例14: __init__
def __init__(self):
# Minimal gtk initialization
self.builder = gtk.Builder()
self.builder.add_from_file("roi_image.glade")
self.builder.connect_signals(self)
# Create a matplotlib figure for the image
self.imageFigure = Figure(figsize=(5,4), dpi=100)
self.imagePlot = self.imageFigure.add_subplot(111)
# Place the matplotlib figures into a container
self.imageCanvas = FigureCanvas(self.imageFigure) # a gtk.DrawingArea
self.builder.get_object('imageViewPort').add(self.imageCanvas)
# Create a matplotlib figure for the plot
self.plotFigure = Figure(figsize=(5,4), dpi=100)
self.plotPlot = self.plotFigure.add_subplot(111)
# Place the matplotlib figures into a container
self.plotCanvas = FigureCanvas(self.plotFigure) # a gtk.DrawingArea
self.builder.get_object('plotViewPort').add(self.plotCanvas)
self.builder.get_object('lowIndexSlider').set_range(0,2047)
self.builder.get_object('lowIndexSlider').set_value(0)
self.builder.get_object('highIndexSlider').set_range(0,2047)
self.builder.get_object('highIndexSlider').set_value(2047)
self.mCurrentLowLimit = 0
self.mCurrentHighLimit = 2047
示例15: __init__
def __init__(self,t_from,t_to):
self.figure = Figure(figsize=(10,2), dpi=80)
self.t_from = t_from
self.t_to = t_to
self.t_diff = math.fabs(t_from - t_to)
self.axis = None
FigureCanvas.__init__(self,self.figure)