text
stringlengths 1
93.6k
|
|---|
self.toolbar.size_hint_y = 0.1
|
layout.add_widget(self.toolbar)
|
return layout
|
def draw_if_interactive():
|
'''Handle whether or not the backend is in interactive mode or not.
|
'''
|
if matplotlib.is_interactive():
|
figManager = Gcf.get_active()
|
if figManager:
|
figManager.canvas.draw_idle()
|
class Show(ShowBase):
|
'''mainloop needs to be overwritten to define the show() behavior for kivy
|
framework.
|
'''
|
def mainloop(self):
|
app = App.get_running_app()
|
if app is None:
|
app = MPLKivyApp(figure=my_canvas, toolbar=toolbar)
|
app.run()
|
show = Show()
|
def new_figure_manager(num, *args, **kwargs):
|
'''Create a new figure manager instance for the figure given.
|
'''
|
# if a main-level app must be created, this (and
|
# new_figure_manager_given_figure) is the usual place to
|
# do it -- see backend_wx, backend_wxagg and backend_tkagg for
|
# examples. Not all GUIs require explicit instantiation of a
|
# main-level app (egg backend_gtk, backend_gtkagg) for pylab
|
FigureClass = kwargs.pop('FigureClass', Figure)
|
thisFig = FigureClass(*args, **kwargs)
|
return new_figure_manager_given_figure(num, thisFig)
|
def new_figure_manager_given_figure(num, figure):
|
'''Create a new figure manager instance for the given figure.
|
'''
|
canvas = FigureCanvasKivy(figure)
|
manager = FigureManagerKivy(canvas, num)
|
global my_canvas
|
global toolbar
|
toolbar = manager.toolbar.actionbar if manager.toolbar else None
|
my_canvas = canvas
|
return manager
|
class RendererKivy(RendererBase):
|
'''The kivy renderer handles drawing/rendering operations. A RendererKivy
|
should be initialized with a FigureCanvasKivy widget. On initialization
|
a MathTextParser is instantiated to generate math text inside a
|
FigureCanvasKivy widget. Additionally a list to store clip_rectangles
|
is defined for elements that need to be clipped inside a rectangle such
|
as axes. The rest of the render is performed using kivy graphics
|
instructions.
|
'''
|
def __init__(self, widget):
|
super(RendererKivy, self).__init__()
|
self.widget = widget
|
self.dpi = widget.figure.dpi
|
self._markers = {}
|
# Can be enhanced by using TextToPath matplotlib, textpath.py
|
self.mathtext_parser = MathTextParser("Bitmap")
|
self.list_goraud_triangles = []
|
self.clip_rectangles = []
|
self.labels_inside_plot = []
|
def contains(self, widget, x, y):
|
'''Returns whether or not a point is inside the widget. The value
|
of the point is defined in x, y as kivy coordinates.
|
'''
|
left = widget.x
|
bottom = widget.y
|
top = widget.y + widget.height
|
right = widget.x + widget.width
|
return (left <= x <= right and
|
bottom <= y <= top)
|
def handle_clip_rectangle(self, gc, x, y):
|
'''It checks whether the point (x,y) collides with any already
|
existent stencil. If so it returns the index position of the
|
stencil it collides with. if the new clip rectangle bounds are
|
None it draws in the canvas otherwise it finds the correspondent
|
stencil or creates a new one for the new graphics instructions.
|
The point x,y is given in matplotlib coordinates.
|
'''
|
x = self.widget.x + x
|
y = self.widget.y + y
|
collides = self.collides_with_existent_stencil(x, y)
|
if collides > -1:
|
return collides
|
new_bounds = gc.get_clip_rectangle()
|
if new_bounds:
|
x = self.widget.x + int(new_bounds.bounds[0])
|
y = self.widget.y + int(new_bounds.bounds[1])
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.