コード例 #1
0
 def create_map_figure(self):
     ax_col = ColorAxis(scale=self.col_scale,
                        label="ratio",
                        tick_format="0.2f")
     return Figure(
         marks=[self.geomap],
         axes=[ax_col],
         title="Wealth of The Netherlands",
         layout={
             "min_width": "400px",
             "width": "auto",
             "min_height": "400px",
             "width": "auto",
         },
     )
コード例 #2
0
ファイル: scatterPlotNode.py プロジェクト: stjordanis/gQuant
    def process(self, inputs):
        """
        Plot the Scatter plot

        Arguments
        -------
         inputs: list
            list of input dataframes.
        Returns
        -------
        Figure

        """
        input_df = inputs[self.INPUT_PORT_NAME]
        if isinstance(input_df, dask_cudf.DataFrame):
            input_df = input_df.compute()  # get the computed value
        num_points = self.conf['points']
        stride = max(len(input_df) // num_points, 1)

        sc_x = scaleMap[self.conf.get('col_x_scale', 'LinearScale')]()
        sc_y = scaleMap[self.conf.get('col_y_scale', 'LinearScale')]()

        x_col = self.conf['col_x']
        y_col = self.conf['col_y']
        ax_y = Axis(label=y_col,
                    scale=sc_y,
                    orientation='vertical',
                    side='left')

        ax_x = Axis(label=x_col,
                    scale=sc_x,
                    num_ticks=10,
                    label_location='end')
        m_chart = dict(top=50, bottom=70, left=50, right=100)
        if 'col_color' in self.conf:
            color_col = self.conf['col_color']
            sc_c1 = ColorScale()
            ax_c = ColorAxis(scale=sc_c1,
                             tick_format='0.2%',
                             label=color_col,
                             orientation='vertical',
                             side='right')
            if isinstance(input_df, (cudf.DataFrame, dask_cudf.DataFrame)):
                scatter = Scatter(
                    x=input_df[x_col][::stride].to_array(),
                    y=input_df[y_col][::stride].to_array(),
                    color=input_df[color_col][::stride].to_array(),
                    scales={
                        'x': sc_x,
                        'y': sc_y,
                        'color': sc_c1
                    },
                    stroke='black')
            else:
                scatter = Scatter(x=input_df[x_col][::stride],
                                  y=input_df[y_col][::stride],
                                  color=input_df[color_col][::stride],
                                  scales={
                                      'x': sc_x,
                                      'y': sc_y,
                                      'color': sc_c1
                                  },
                                  stroke='black')
            fig = Figure(axes=[ax_x, ax_c, ax_y],
                         marks=[scatter],
                         fig_margin=m_chart,
                         title=self.conf['title'])

        else:
            if isinstance(input_df, (cudf.DataFrame, dask_cudf.DataFrame)):
                scatter = Scatter(x=input_df[x_col][::stride].to_array(),
                                  y=input_df[y_col][::stride].to_array(),
                                  scales={
                                      'x': sc_x,
                                      'y': sc_y
                                  },
                                  stroke='black')
            else:
                scatter = Scatter(x=input_df[x_col][::stride],
                                  y=input_df[y_col][::stride],
                                  scales={
                                      'x': sc_x,
                                      'y': sc_y
                                  },
                                  stroke='black')
            fig = Figure(axes=[ax_x, ax_y],
                         marks=[scatter],
                         fig_margin=m_chart,
                         title=self.conf['title'])
        return {self.OUTPUT_PORT_NAME: fig}
コード例 #3
0
ファイル: cyplot.py プロジェクト: orpheus92/CyQuery
    def create_fig(self, ts):

        if self.ptype != 'PCA' and self.dims == None:
            ts.sort_index(inplace=True)
            df = ts.reset_index()  # time = ts.Time

        else:
            df = ts
        self.xd = df[self.xlabel]
        self.yd = df[self.cols].T

        if self.ptype == 'PCA' or self.dims is not None:
            pplt = Scatter(x=self.xd.values.ravel(), y=self.yd.values.ravel(), scales={'x': self.xScale, \
            'y': self.yScale, 'color': ColorScale(scheme=self.scheme)}, selected_style={'opacity': '1'}, \
            unselected_style={'opacity': '0.2'},color = self.colors, default_size=32)

        elif not self.ptype:
            pplt = Lines(x=self.xd, y=self.yd, scales={'x': self.xScale, 'y': self.yScale}, labels=self.legends,
                         display_legend=True, line_style=self.linestyle, stroke_width = 1, marker = 'circle', \
                         interpolation = self.interp)
            # {‘linear’, ‘basis’, ‘cardinal’, ‘monotone’}
        else:
            pplt = Lines(x=self.xd, y=self.yd, scales={'x': self.xScale, 'y': self.yScale}, labels=self.legends, \
                         display_legend=True, line_style=self.linestyle, selected_style={'opacity': '1'}, \
                         unselected_style={'opacity': '0.2'},interpolation=self.interp)
            # enable_hover=True)  # axes_options=axes_options)

        x_axis = Axis(scale=self.xScale, label=self.xlabel, grid_lines='none')
        y_axis = Axis(scale=self.yScale,
                      label=self.ylabel,
                      orientation='vertical',
                      grid_lines='none')
        c_axis = ColorAxis(scale=ColorScale(scheme=self.scheme),
                           orientation='vertical',
                           side='right')

        axis = [x_axis, y_axis, c_axis] if isinstance(
            pplt, Scatter) else [x_axis, y_axis]

        if self.debug:
            margin = dict(top=0, bottom=40, left=50, right=50)
        else:
            margin = dict(top=0, bottom=50, left=50, right=50)

        self.fig = Figure(marks=[pplt],
                          axes=axis,
                          legend_location='top-right',
                          fig_margin=margin)  # {'top':50,'left':60})

        if self.debug:
            self.deb = HTML()

        y = getattr(self, "vbox", None)
        if y is not None:
            box_layout = Layout(display='flex',
                                flex_flow='column',
                                align_items='stretch')
            if self.debug:
                self.vbox = VBox(
                    [self.selection_interacts, self.fig, self.deb],
                    layout=box_layout)
            else:
                self.vbox = VBox([self.selection_interacts, self.fig],
                                 layout=box_layout)
コード例 #4
0
        4: 21.,
        398: 23.,
        156: 42.,
        124: 78.,
        76: 98.
    },
    'scales': {
        'projection': sc_geo,
        'color': sc_c1
    },
    'colors': {
        'default_color': 'Grey'
    }
}

axis = ColorAxis(scale=sc_c1)

chloro_map = Map(map_data=topo_load('map_data/WorldMap.json'), **map_styles)
fig = plt.figure(marks=[chloro_map], axes=[axis], title='Choropleth Example')
if kommune.check_isnotebook():
    display(fig)
"""# Example 4"""
#sc_geo = Mercator(center=(-110,60), scale_factor=500)
sc_geo = AlbersUSA(translate=(500, 300), scale_factor=1200)

data = os.getcwd() + os.sep + "Data" + os.sep + "USCountiesMap.topojson"
map_mark = Map(map_data=topo_load(data), scales={'projection': sc_geo})
map_fig_1 = plt.figure(marks=[map_mark],
                       fig_color='deepskyblue',
                       title='Test for US map')
コード例 #5
0
    def __init__(
        self,
        measures,
        x=None,
        y=None,
        c=None,
        mouseover=False,
        host="localhost",
        port=4090,
    ):
        """Interactive scatter plot visualisation - this is a base class,
        use either `ROIScatterViz` for one image with multiple ROIs
        or `ImageScatterViz` for a scatterplot with multiple images
        """
        self.port = port
        self.measures = measures
        self.columns = list(measures.columns)
        x_col = x if x else self.columns[0]
        y_col = y if y else self.columns[1]
        c_col = c if c else self.columns[2]

        selector_layout = widgets.Layout(height="40px", width="100px")
        self.x_selecta = widgets.Dropdown(
            options=self.columns,
            value=x_col,
            description="",
            disabled=False,
            layout=selector_layout,
        )
        self.y_selecta = widgets.Dropdown(
            options=self.columns,
            value=y_col,
            description="",
            disabled=False,
            layout=selector_layout,
        )

        self.c_selecta = widgets.Dropdown(
            options=self.columns,
            value=c_col,
            description="",
            disabled=False,
            layout=selector_layout,
        )

        self.sheet = widgets.Output()
        self.thumbs = {}
        self.goto = widgets.HTML("")
        if is_datetime(self.measures, x_col):
            x_sc = DateScale()
        else:
            x_sc = LinearScale()

        if is_datetime(self.measures, y_col):
            y_sc = DateScale()
        else:
            y_sc = LinearScale()

        if is_datetime(self.measures, c_col):
            c_sc = DateColorScale(scheme="viridis")
        else:
            c_sc = ColorScale()

        self.scat = Scatter(
            x=self.measures[self.x_selecta.value],
            y=self.measures[self.y_selecta.value],
            color=self.measures[self.c_selecta.value],
            scales={
                "x": x_sc,
                "y": y_sc,
                "color": c_sc,
            },
            names=self.measures.index,
            display_names=False,
            fill=True,
            default_opacities=[
                0.8,
            ],
        )
        self.ax_x = Axis(scale=x_sc, label=self.x_selecta.value)
        self.ax_y = Axis(scale=y_sc,
                         label=self.y_selecta.value,
                         orientation="vertical")
        self.ax_c = ColorAxis(
            scale=c_sc,
            label=self.c_selecta.value,
            orientation="vertical",
            offset={
                "scale": y_sc,
                "value": 100
            },
        )
        self.fig = Figure(
            marks=[
                self.scat,
            ],
            axes=[self.ax_x, self.ax_y, self.ax_c],
        )
        self.scat.on_element_click(self.goto_db)
        self.scat.on_element_click(self.show_data)
        if mouseover:
            self.scat.on_hover(self.show_thumb)
            self.scat.tooltip = widgets.HTML("")
        self.x_selecta.observe(self.update_scatter)
        self.y_selecta.observe(self.update_scatter)
        self.c_selecta.observe(self.update_scatter)
        self.connector = OMEConnect(host=host, port=4064)
        self.connector.gobtn.on_click(self.setup_graph)
        super().__init__([self.connector])