1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
# -*- coding: utf-8 -*-
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
from ..scene import SceneCanvas
from .plotwidget import PlotWidget
class Fig(SceneCanvas):
"""Create a figure window
Parameters
----------
bgcolor : instance of Color
Color to use for the background.
size : tuple
Size of the figure window in pixels.
show : bool
If True, show the window.
**kwargs : dict
Keywoard arguments to pass to `SceneCanvas` base class.
Notes
-----
You can create a Figure, PlotWidget, and diagonal line plot like this::
>>> from vispy.plot import Fig
>>> fig = Fig()
>>> ax = fig[0, 0] # this creates a PlotWidget
>>> ax.plot([[0, 1], [1, 0]])
See the gallery for many other examples.
See Also
--------
PlotWidget : the axis widget for plotting
SceneCanvas : the super class
"""
def __init__(self, bgcolor='w', size=(800, 600), show=True,
keys='interactive', **kwargs):
self._plot_widgets = []
self._grid = None # initialize before the freeze occurs
super(Fig, self).__init__(bgcolor=bgcolor, keys=keys,
show=show, size=size, **kwargs)
self._grid = self.central_widget.add_grid()
self._grid._default_class = PlotWidget
@property
def plot_widgets(self):
"""List of the associated PlotWidget instances"""
return tuple(self._plot_widgets)
def __getitem__(self, idxs):
"""Get an axis"""
pw = self._grid.__getitem__(idxs)
self._plot_widgets += [pw]
return pw
|