示例#1
0
    def _configure_2d(self, fg_color=None):
        if self._configured:
            return
        if fg_color is None:
            fg = self._fg
        else:
            fg = fg_color
        self.yaxis = scene.AxisWidget(orientation='left',
                                      text_color=fg,
                                      axis_color=fg,
                                      tick_color=fg)
        self.yaxis.stretch = (0.1, 1)
        self.grid.add_widget(self.yaxis, row=2, col=2)

        self.ylabel = scene.Label("", rotation=-90)
        self.ylabel.stretch = (0.05, 1)
        self.grid.add_widget(self.ylabel, row=2, col=1)

        self.xaxis = scene.AxisWidget(orientation='bottom',
                                      text_color=fg,
                                      axis_color=fg,
                                      tick_color=fg)
        self.xaxis.stretch = (1, 0.1)
        self.grid.add_widget(self.xaxis, row=3, col=3)

        self.xlabel = scene.Label("")
        self.xlabel.stretch = (1, 0.05)
        self.grid.add_widget(self.xlabel, row=4, col=3)

        self.view.camera = SCTAudioCamera(zoom=None, pan=None)
        self.camera = self.view.camera

        self.xaxis.link_view(self.view)
        self.yaxis.link_view(self.view)
        self._configured = True
示例#2
0
 def _setup_xaxis(self, xlabel):
     self.xaxis = scene.AxisWidget(orientation='bottom', text_color=xlabel.color, axis_color=xlabel.color, tick_color=xlabel.color)
     xaxis_widget = self.grid.add_widget(self.xaxis, row=1, col=2)
     xaxis_widget.height_max = xlabel.dim
     self.xlabel = scene.Label(xlabel.text, font_size=xlabel.font_size, color=xlabel.color)
     xlabel_widget = self.grid.add_widget(self.xlabel, row=2, col=2)
     xlabel_widget.height_max = xlabel.dim
示例#3
0
 def _setup_yaxis(self, ylabel):
     self.ylabel = scene.Label(ylabel.text, font_size=ylabel.font_size, color=ylabel.color, rotation=-90)
     ylabel_widget = self.grid.add_widget(self.ylabel, row=0, col=0)
     ylabel_widget.width_max = ylabel.dim
     self.yaxis = scene.AxisWidget(orientation='left', text_color=ylabel.color, axis_color=ylabel.color, tick_color=ylabel.color, )
     yaxis_widget = self.grid.add_widget(self.yaxis, row=0, col=1)
     yaxis_widget.width_max = ylabel.dim
示例#4
0
    def __init__(self, *args, **kwargs):
        self._fg = kwargs.pop('fg_color', 'k')
        self.grid = None
        self.camera = None
        self.title = None
        self.yaxis = None
        self.xaxis = None
        self._configured = False
        self.visuals = []
        self.section_y_x = None
        self.linked = False
        self.data = None

        super(PlotWidget, self).__init__(*args, **kwargs)
        self.grid = self.add_grid(spacing=0, margin=10)

        self.title = scene.Label("", font_size=16, color="#ff0000")
示例#5
0
    def init_axes(self, **kwargs):
        self.grid = self.canvas.central_widget.add_grid(margin=10)
        self.grid.spacing = 0
        self.r = 0

        self.title = scene.Label(kwargs.get("title", ""), color="w")
        self.title.height_max = 40
        self.grid.add_widget(self.title, row=0, col=0, col_span=2)
        self.r += 1
        self.yaxis = scene.AxisWidget(
            orientation="left",
            axis_label=kwargs.get("y_label", ""),
            axis_font_size=10,
            axis_label_margin=40,  #20?
            tick_label_margin=15,
        )
        self.yaxis.width_max = 80
        self.grid.add_widget(self.yaxis, row=self.r, col=0)

        self.xaxis = scene.AxisWidget(
            orientation="bottom",
            axis_label=kwargs.get("x_label", ""),
            axis_font_size=10,
            axis_label_margin=40,
            tick_label_margin=15,
        )
        self.xaxis.height_max = 80
        self.grid.add_widget(self.xaxis, row=self.r + 1, col=1)

        right_padding = self.grid.add_widget(row=self.r, col=2, row_span=1)
        right_padding.width_max = 50

        self.view = self.grid.add_view(row=self.r, col=1, border_color="white")
        self.view.camera = "panzoom"
        self.view.camera.set_default_state()

        self.xaxis.link_view(self.view)
        self.yaxis.link_view(self.view)
示例#6
0
    def __init__(self, *args, **kwargs):
        self._fg = kwargs.pop('fg_color', 'k')
        self.grid = None
        self.camera = None
        self.title = None
        self.title_widget = None
        self.yaxis = None
        self.xaxis = None
        self.xlabel = None
        self.ylabel = None
        self._configured = False
        self.visuals = []
        self.section_y_x = None

        self.cbar_top = None
        self.cbar_bottom = None
        self.cbar_left = None
        self.cbar_right = None

        super(PlotWidget, self).__init__(*args, **kwargs)
        self.grid = self.add_grid(spacing=0, margin=10)

        self.title = scene.Label("", font_size=16, color="#ff0000")
        self._configure_2d()
示例#7
0
# Copyright (c) 2015, Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
"""
Test automatic layout of multiple viewboxes using Grid.
"""
import sys
import numpy as np

from vispy import scene, app

canvas = scene.SceneCanvas(keys='interactive', size=(600, 600), show=True)
grid = canvas.central_widget.add_grid(margin=10)
grid.spacing = 0

title = scene.Label("Plot Title", color='white')
title.height_max = 40
grid.add_widget(title, row=0, col=0, col_span=2)

yaxis = scene.AxisWidget(orientation='left',
                         axis_label='Y Axis',
                         axis_font_size=12,
                         axis_label_margin=50,
                         tick_label_margin=5)
yaxis.width_max = 80
grid.add_widget(yaxis, row=1, col=0)

xaxis = scene.AxisWidget(orientation='bottom',
                         axis_label='X Axis',
                         axis_font_size=12,
                         axis_label_margin=50,
示例#8
0
# Copyright (c) 2015, Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
"""
Test automatic layout of multiple viewboxes using Grid.
"""
import sys
import numpy as np

from vispy import scene, app

canvas = scene.SceneCanvas(keys='interactive', size=(600, 600), show=True)
grid = canvas.central_widget.add_grid(margin=10)
grid.spacing = 0

title = scene.Label("Plot Title", color='white')
title.height_max = 40
grid.add_widget(title, row=0, col=0, col_span=3)

yaxis = scene.AxisWidget(orientation='left')
yaxis.width_max = 40
grid.add_widget(yaxis, row=1, col=1)

ylabel = scene.Label('Y Axis', rotation=-90, color='white')
ylabel.width_max = 40
grid.add_widget(ylabel, row=1, col=0)

xaxis = scene.AxisWidget(orientation='bottom')
xaxis.height_max = 40
grid.add_widget(xaxis, row=2, col=2)
示例#9
0
    def __init__(self,
                 axis=False,
                 title=None,
                 xlabel=None,
                 ylabel=None,
                 title_font_size=15.,
                 axis_font_size=12.,
                 axis_color='black',
                 tick_font_size=10.,
                 name=None,
                 x_height_max=80,
                 y_width_max=80,
                 axis_label_margin=50,
                 tick_label_margin=5,
                 rpad=20.,
                 bgcolor='white',
                 add_cbar=False,
                 cargs={},
                 xargs={},
                 yargs={},
                 cbargs={},
                 show=False,
                 camera=None,
                 shortcuts={}):
        """Init."""
        self._axis = axis
        self._title = title
        self._xlabel = xlabel
        self._ylabel = ylabel
        self._title_font_size = title_font_size
        self._axis_font_size = axis_font_size
        self._axis_color = axis_color
        self._tick_font_size = tick_font_size
        self._name = name
        self._x_height_max = x_height_max
        self._y_width_max = y_width_max
        self._axis_label_margin = axis_label_margin
        self._tick_label_margin = tick_label_margin
        self._bgcolor = bgcolor
        self._visible = show

        # ########################## MAIN CANVAS ##########################
        self.canvas = scene.SceneCanvas(keys='interactive',
                                        bgcolor=bgcolor,
                                        show=show,
                                        title=name,
                                        **cargs)

        # ########################## AXIS ##########################
        if axis:  # add axis to canvas
            # ----------- GRID -----------
            grid = self.canvas.central_widget.add_grid(margin=10)
            grid.spacing = 0

            # ----------- COLOR -----------
            axcol = color2vb(axis_color)
            kw = {
                'axis_label_margin': axis_label_margin,
                'tick_label_margin': tick_label_margin,
                'axis_font_size': axis_font_size,
                'axis_color': axcol,
                'tick_color': axcol,
                'text_color': axcol,
                'tick_font_size': tick_font_size
            }

            # ----------- TITLE -----------
            self._titleObj = scene.Label(title,
                                         color=axcol,
                                         font_size=title_font_size)
            self._titleObj.height_max = 40
            grid.add_widget(self._titleObj, row=0, col=0, col_span=2)

            # ----------- Y-AXIS -----------
            yargs.update(kw)
            self.yaxis = scene.AxisWidget(orientation='left',
                                          domain=(0, 129),
                                          axis_label=ylabel,
                                          **yargs)
            self.yaxis.width_max = y_width_max
            grid.add_widget(self.yaxis, row=1, col=0)

            # ----------- X-AXIS -----------
            xargs.update(kw)
            self.xaxis = scene.AxisWidget(orientation='bottom',
                                          axis_label=xlabel,
                                          **xargs)
            self.xaxis.height_max = x_height_max
            grid.add_widget(self.xaxis, row=2, col=1)

            # ----------- MAIN -----------
            self.wc = grid.add_view(row=1, col=1, camera=camera)
            self.grid = grid

            # ----------- LINK -----------
            self.xaxis.link_view(self.wc)
            self.yaxis.link_view(self.wc)

            # ----------- CBAR -----------
            rpad_col = 0
            if add_cbar:
                self.wc_cbar = grid.add_view(row=1, col=2)
                self.wc_cbar.width_max = 150.
                self.cbar = CbarVisual(width=.2, parent=self.wc_cbar.scene)
                rpad_col += 1

            # ----------- RIGHT PADDING -----------
            self._rpad = grid.add_widget(row=1, col=2 + rpad_col, row_span=1)
            self._rpad.width_max = rpad

        else:  # Ignore axis
            self.wc = self.canvas.central_widget.add_view(camera=camera)
示例#10
0
    def _configure_2d(self, fg_color=None):
        if self._configured:
            return

        if fg_color is None:
            fg = self._fg
        else:
            fg = fg_color

        #     c0        c1      c2      c3      c4      c5         c6
        #  r0 +---------+-------+-------+-------+-------+---------+---------+
        #     |         |                       | title |         |         |
        #  r1 |         +-----------------------+-------+---------+         |
        #     |         |                       | cbar  |         |         |
        #  r2 |         +-------+-------+-------+-------+---------+         |
        #     |         | cbar  | ylabel| yaxis |  view | cbar    | padding |
        #  r3 | padding +-------+-------+-------+-------+---------+         |
        #     |         |                       | xaxis |         |         |
        #  r4 |         +-----------------------+-------+---------+         |
        #     |         |                       | xlabel|         |         |
        #  r5 |         +-----------------------+-------+---------+         |
        #     |         |                       | cbar  |         |         |
        #  r6 |---------+-----------------------+-------+---------+---------|
        #     |                           padding                           |
        #     +---------+-----------------------+-------+---------+---------+

        default = False
        get_func = CONF.get_default if default else CONF.get
        section = 'image_viewer'
        padding_left_width = get_func(section, 'padding_left_width')
        padding_right_width = get_func(section, 'padding_right_width')
        padding_bottom_height = get_func(section, 'padding_bottom_height')
        cbar_top_height = get_func(section, 'cbar_top_height')
        cbar_bottom_height = get_func(section, 'cbar_bottom_height')
        cbar_left_width = get_func(section, 'cbar_left_width')
        cbar_right_width = get_func(section, 'cbar_right_width')
        title_widget_height = get_func(section, 'title_widget_height')
        xlabel_widget_height = get_func(section, 'xlabel_widget_height')
        ylabel_widget_width = get_func(section, 'ylabel_widget_width')
        xaxis_widget_height = get_func(section, 'xaxis_widget_height')
        yaxis_widget_width = get_func(section, 'yaxis_widget_width')

        # padding left
        padding_left = self.grid.add_widget(None, row=0, row_span=5, col=0)
        padding_left.width_min = padding_left_width[0]
        padding_left.width_max = padding_left_width[1]

        # padding right
        padding_right = self.grid.add_widget(None, row=0, row_span=5, col=6)
        padding_right.width_min = padding_right_width[0]
        padding_right.width_max = padding_right_width[1]

        # padding right
        padding_bottom = self.grid.add_widget(None, row=6, col=0, col_span=6)
        padding_bottom.height_min = padding_bottom_height[0]
        padding_bottom.height_max = padding_bottom_height[1]

        # row 0
        # title - column 4 to 5
        self.title_widget = self.grid.add_widget(self.title, row=0, col=4)
        self.title_widget.height_min = title_widget_height[0]
        self.title_widget.height_max = title_widget_height[1]

        # row 1
        # colorbar - column 4 to 5
        self.cbar_top = self.grid.add_widget(None, row=1, col=4)
        self.cbar_top.height_max = cbar_top_height[1]

        # row 2, xlabel
        # xlabel - column 4
        self.xlabel = scene.Label("xlabel")
        xlabel_widget = self.grid.add_widget(self.xlabel, row=2, col=4)
        xlabel_widget.height_min = xlabel_widget_height[0]
        xlabel_widget.height_max = xlabel_widget_height[1]

        # row 3, xaxis

        # row 4
        # colorbar_left - column 1
        # ylabel - column 2
        # yaxis - column 3
        # view - column 4
        # colorbar_right - column 5
        self.cbar_left = self.grid.add_widget(None, row=4, col=1)
        self.cbar_left.width_max = cbar_left_width[1]

        self.ylabel = scene.Label("ylabel", rotation=-90)
        ylabel_widget = self.grid.add_widget(self.ylabel, row=4, col=2)
        ylabel_widget.width_min = ylabel_widget_width[0]
        ylabel_widget.width_max = ylabel_widget_width[1]

        self.yaxis = scene.AxisWidget(orientation='left',
                                      text_color=fg,
                                      axis_color=fg,
                                      tick_color=fg)

        yaxis_widget = self.grid.add_widget(self.yaxis, row=4, col=3)
        yaxis_widget.width_min = yaxis_widget_width[0]
        yaxis_widget.width_max = yaxis_widget_width[0]

        self.view = self.grid.add_view(row=4,
                                       col=4,
                                       border_color='grey',
                                       bgcolor="#efefef")
        self.view.camera = 'panzoom'
        self.camera = self.view.camera

        self.cbar_right = self.grid.add_widget(None, row=4, col=5)
        self.cbar_right.width_max = cbar_right_width[1]

        # row 3
        # xaxis - column 4
        self.xaxis = scene.AxisWidget(orientation='top',
                                      text_color=fg,
                                      axis_color=fg,
                                      tick_color=fg)
        xaxis_widget = self.grid.add_widget(self.xaxis, row=3, col=4)
        xaxis_widget.height_min = xaxis_widget_height[0]
        xaxis_widget.height_max = xaxis_widget_height[1]

        # row 4
        # xlabel - column 4
        #        self.xlabel = scene.Label("xlabel")
        #        xlabel_widget = self.grid.add_widget(self.xlabel, row=4, col=4)
        #        xlabel_widget.height_min = 20
        #        xlabel_widget.height_max = 40

        # row 5
        self.cbar_bottom = self.grid.add_widget(None, row=5, col=4)
        self.cbar_bottom.height_max = cbar_bottom_height[1]

        self._configured = True
        self.xaxis.link_view(self.view)
        self.yaxis.link_view(self.view)
示例#11
0
文件: main.py 项目: phildong/isovis
 def __init__(self, data, vid, *args, **kwargs) -> None:
     # init
     scene.SceneCanvas.__init__(self, *args, keys="interactive", **kwargs)
     self.unfreeze()
     self.grid = self.central_widget.add_grid(margin=10)
     cn = CONFIG["col_names"]
     # normalize data
     data_vals = data[[cn["x"], cn["y"], cn["z"]]].values
     dmax = data_vals.max()
     dmin = data_vals.min()
     data[[cn["x"], cn["y"], cn["z"]]] = (data_vals - dmin) / (dmax - dmin)
     # color data
     col_cls = CONFIG["col_names"]["class"]
     col_cmap = CONFIG["col_names"].get("color", None)
     cmaps = CONFIG.get("cmap", None)
     if col_cmap is not None and cmaps is not None:
         data["cweak"] = 0
         data["cstrong"] = 0
         if type(cmaps) is str:
             pass
         else:
             for lab, cmap in cmaps.items():
                 try:
                     cm = ScalarMappable(cmap=cmap)
                     data.loc[data[col_cls] == lab, "cweak"] = [
                         to_hex(c)
                         for c in cm.to_rgba(data.loc[data[col_cls] == lab,
                                                      col_cmap])
                     ]
                     data.loc[data[col_cls] == lab, "cstrong"] = [
                         to_hex(c)
                         for c in cm.to_rgba(data.loc[data[col_cls] == lab,
                                                      col_cmap])
                     ]
                 except ValueError:
                     data.loc[data[col_cls] == lab, "cweak"] = cmap
                     data.loc[data[col_cls] == lab, "cstrong"] = cmap
     else:
         data["cweak"] = data[col_cls].map({
             k: v
             for k, v in zip(data[col_cls].unique(),
                             cycle(Category20_20[0::2]))
         })
         data["cstrong"] = data[col_cls].map({
             k: v
             for k, v in zip(data[col_cls].unique(),
                             cycle(Category20_20[1::2]))
         })
     # scatter plot
     sct_title = scene.Label("State Space", color="white")
     sct_title.height_max = 30
     self.grid.add_widget(sct_title, row=0, col=0)
     self.sct_view = self.grid.add_view(row=1, col=0, border_color="white")
     self.sct_data = data
     self.mks = scene.Markers(
         parent=self.sct_view.scene,
         pos=self.sct_data[[cn["x"], cn["y"], cn["z"]]].values,
         face_color=ColorArray(list(self.sct_data["cweak"].values)),
         size=4,
         edge_width=0,
     )
     self.mks.attach(Alpha(0.6))
     self.cur_mks = scene.Markers(
         parent=self.sct_view.scene,
         pos=np.expand_dims(
             self.sct_data.iloc[0, :][[cn["x"], cn["y"], cn["z"]]].values,
             axis=0),
         face_color=self.sct_data.iloc[0, :]["cstrong"],
         size=8,
         edge_color="white",
     )
     self.cur_mks.set_gl_state(depth_test=False)
     self.axes = scene.XYZAxis(parent=self.sct_view.scene, width=100)
     self.sct_view.camera = "arcball"
     # behav cam
     im_title = scene.Label("Behavior Image", color="white")
     im_title.height_max = 30
     self.grid.add_widget(im_title, row=0, col=1)
     self.im_view = self.grid.add_view(row=1, col=1, border_color="white")
     self.im_data = vid
     fm0 = vid[int(self.sct_data.loc[0, CONFIG["col_names"]["frame"]])]
     self.im = scene.Image(parent=self.im_view.scene, data=fm0)
     self.im_view.camera = "panzoom"
     self.im_view.camera.flip = (False, True, False)
     self.im_view.camera.rect = (0, 0, fm0.shape[1], fm0.shape[0])
     self.im_view.camera.aspect = 1
示例#12
0
    def __init__(self,
                 axis=True,
                 x_label='',
                 x_heightMax=80,
                 y_label='',
                 y_widthMax=80,
                 font_size=12,
                 color='white',
                 title='',
                 axis_label_margin=50,
                 tick_label_margin=5,
                 name='',
                 bgcolor=(.9, .9, .9),
                 cargs={},
                 xargs={},
                 yargs={}):
        """Init."""
        # Save variables :
        self._axis = axis
        self._title = title
        self._xlabel = x_label
        self._ylabel = y_label

        # Create the main canvas :
        self.canvas = scene.SceneCanvas(keys='interactive',
                                        bgcolor=bgcolor,
                                        show=False,
                                        title=name,
                                        **cargs)

        # Add axis :
        if axis:
            # Create a grid :
            grid = self.canvas.central_widget.add_grid(margin=10)
            grid.spacing = 0

            # Add a title :
            self._titleObj = scene.Label(title, color=color)
            self._titleObj.height_max = 40
            grid.add_widget(self._titleObj, row=0, col=0, col_span=2)

            # Add y-axis :
            self.yaxis = scene.AxisWidget(orientation='left',
                                          domain=(0, 129),
                                          axis_label=y_label,
                                          axis_font_size=font_size,
                                          axis_label_margin=axis_label_margin,
                                          tick_label_margin=tick_label_margin,
                                          **yargs)
            self.yaxis.width_max = y_widthMax
            grid.add_widget(self.yaxis, row=1, col=0)

            # Add x-axis :
            self.xaxis = scene.AxisWidget(orientation='bottom',
                                          axis_label=x_label,
                                          axis_font_size=font_size,
                                          axis_label_margin=axis_label_margin,
                                          tick_label_margin=tick_label_margin,
                                          **xargs)
            self.xaxis.height_max = x_heightMax
            grid.add_widget(self.xaxis, row=2, col=1)

            # Add right padding :
            self._rpad = grid.add_widget(row=1, col=2, row_span=1)
            self._rpad.width_max = 50

            # Main plot :
            self.wc = grid.add_view(row=1, col=1, border_color=color)

        # Ignore axis :
        else:
            self.wc = self.canvas.central_widget.add_view()