Python plotly.graph_objs.FigureWidget() Examples

The following are 7 code examples of plotly.graph_objs.FigureWidget(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module plotly.graph_objs , or try the search function .
Example #1
Source File: visuals.py    From python-esppy with Apache License 2.0 5 votes vote down vote up
def create(self):
        self.createContent()

        if self._data != None:
            self._layout = go.Layout()

            margin = 20
            self._layout["margin"] = dict(l=margin,r=margin,b=margin,t=margin)

            xRange = self.getOpt("xrange")
            if xRange != None:
                self._layout["xaxis"]["range"] = xRange
            yRange = self.getOpt("yrange")
            if yRange != None:
                self._layout["yaxis"]["range"] = yRange

            self._layout["xaxis"]["showticklabels"] = self.getOpt("showticks",True)
            self._layout["xaxis"]["showline"] = False

            self._figure = go.FigureWidget(data=self._data,layout=self._layout)

            children = [self._banner,self._figure]

            if self.getOpt("show_controls",False):
                if self._controls == None:
                    self._controls = ControlPanel(self._datasource) 
                children.append(self._controls)

            self.children = children

        self.draw(None,True) 
Example #2
Source File: plotlyviz.py    From kepler-mapper with MIT License 5 votes vote down vote up
def summary_fig(
    mapper_summary,
    width=600,
    height=500,
    top=60,
    left=20,
    bottom=60,
    right=20,
    bgcolor="rgb(240,240,240)",
):
    """Define a dummy figure that displays info on the algorithms and
       sklearn class instances or methods used

       Returns a FigureWidget object representing the figure
    """
    text = _text_mapper_summary(mapper_summary)

    data = [
        dict(
            type="scatter",
            x=[0, width],
            y=[height, 0],
            mode="text",
            text=[text, ""],
            textposition="bottom right",
            hoverinfo="none",
        )
    ]

    layout = dict(
        title="Algorithms and scikit-learn objects/methods",
        width=width,
        height=height,
        font=dict(size=12),
        xaxis=dict(visible=False),
        yaxis=dict(visible=False, range=[0, height + 5]),
        margin=dict(t=top, b=bottom, l=left, r=right),
        plot_bgcolor=bgcolor,
    )

    return go.FigureWidget(data=data, layout=layout) 
Example #3
Source File: visuals.py    From python-esppy with Apache License 2.0 4 votes vote down vote up
def createContent(self):
        if self.hasOpt("center"):
            self._map.center = self.getOpt("center")
        if self.hasOpt("zoom"):
            self._map.zoom = self.getOpt("zoom")

        self._lat = self.getOpt("lat")
        if self._lat == None:
            raise Exception("you must specify the lat property")

        self._lon = self.getOpt("lon")
        if self._lon == None:
            raise Exception("you must specify the lon property")

        #if len(self._circles) > 0:
            #for o in self._circles:
                #self._map.add_layer(o["layers"])

        #if len(self._polygons) > 0:
            #for o in self._polygons:
                #self._map.add_layer(o["layers"])

        self._colors = None

        if self.hasOpt("colormap"):
            self._colors = tools.Colors(colormap=self.getOpt("colormap"))
        elif self.hasOpt("colors"):
            self._colors = tools.Colors(colors=self.getOpt("colors"))
        else:
            self._colors = self._visuals._colors

        if self._colors != None:
            if self.hasOpt("color_range"):
                range = self.getOpt("color_range")
                self._colorRange = tools.ColorRange(self._colors,range[0],range[1])

        components = []

        components.append(self._banner)

        colorbar = None

        if self.hasOpt("color"):
            #data = go.Scatter(x=[None],y=[None],marker=dict(colorscale=self._visuals._colors.colorscale,showscale=True,cmin=-5,cmax=5,colorbar=dict(xpad=0,ypad=0,ticks="")))
            data = go.Scatter(x=[None],y=[None],marker=dict(colorscale=self._visuals._colors.colorscale,showscale=True,colorbar=dict(thickness=30)))
            layout = dict(xaxis=dict(visible=False),yaxis=dict(visible=False),showlegend=False)
            #self._colorbar = go.FigureWidget(data=data,layout=layout)
            #colorbar = widgets.Box([self._colorbar],layout=widgets.Layout(width="150px",margin="0px",padding="0px"))

        if colorbar != None:
            components.append(widgets.HBox([self._map,colorbar]))
        else:
            components.append(self._map)

        self.children = components 
Example #4
Source File: visuals.py    From python-esppy with Apache License 2.0 4 votes vote down vote up
def create(self):
        size = self._gauge.getOpt("size",300)

        self._layout = go.Layout(width=size,height=size)

        self._data = []

        self._tics = go.Pie(values=self._gauge._ticValues,labels=self._gauge._ticLabels,
            marker=dict(colors=["rgba(0,0,0,0)"] * (self._gauge._segments + 10),line_width = 0),
            direction="clockwise",
            rotation=int((((self._gauge._shape + 10) / 100) * 360) / 2),
            hole=self._gauge.getOpt("center_size",.40),
            sort=False,
            showlegend=False,
            hoverinfo="none",
            textposition="outside",
            textinfo="label")

        self._data.append(self._tics)

        self._intervals = go.Pie(values=self._gauge._intervalValues,
            labels=self._gauge._intervalLabels,
            text=self._gauge._segmentLabels,
            marker=dict(line_width=self._gauge.getOpt("line_width",4)),
            marker_colors=self._gauge._intervalColors,
            hole=self._gauge.getOpt("center_size",.40),
            sort=False,
            direction="clockwise",
            rotation=int(((self._gauge._shape / 100) * 360) / 2),
            showlegend=False,
            hoverinfo="none",
            textposition="inside",
            textinfo="text")

        self._data.append(self._intervals)

        margin = self._gauge.getOpt("margin",30)
        self._layout["margin"] = dict(l=margin,r=margin,b=margin,t=margin)

        #self._layout["paper_bgcolor"] = "#e8e8e8"
        #self._layout["plot_bgcolor"] = "blue"
        #self._layout["paper_bgcolor"] = "rgba(0,0,0,0)"
        self._layout["plot_bgcolor"] = "rgba(0,0,0,0)"

        self._figure = go.FigureWidget(data=self._data,layout=self._layout)
 
        height = size
        height += 30
        #self.children = [self._title,self._figure],layout=widgets.Layout(border="1px solid #d8d8d8",width=str(size) + "px",height=str(height) + "px")
        self.children = [self._title,self._figure] 
Example #5
Source File: plotlyviz.py    From kepler-mapper with MIT License 4 votes vote down vote up
def node_hist_fig(
    node_color_distribution,
    title="Graph Node Distribution",
    width=400,
    height=300,
    top=60,
    left=25,
    bottom=60,
    right=25,
    bgcolor="rgb(240,240,240)",
    y_gridcolor="white",
):
    """Define the plotly plot representing the node histogram
    
    Parameters
    ----------
    node_color_distribution: list of dicts describing the build_histogram
    width, height: integers -  width and height of the histogram FigureWidget
    left, top, right, bottom: ints; number of pixels around the FigureWidget
    bgcolor: rgb of hex color code for the figure background color
    y_gridcolor: rgb of hex color code for the yaxis y_gridcolor

    Returns
    -------
    FigureWidget object representing the histogram of the graph nodes
    """

    text = [
        "{perc}%".format(**locals())
        for perc in [d["perc"] for d in node_color_distribution]
    ]

    pl_hist = go.Bar(
        y=[d["height"] for d in node_color_distribution],
        marker=dict(color=[d["color"] for d in node_color_distribution]),
        text=text,
        hoverinfo="y+text",
    )

    hist_layout = dict(
        title=title,
        width=width,
        height=height,
        font=dict(size=12),
        xaxis=dict(showline=True, zeroline=False, showgrid=False, showticklabels=False),
        yaxis=dict(showline=False, gridcolor=y_gridcolor, tickfont=dict(size=10)),
        bargap=0.01,
        margin=dict(l=left, r=right, b=bottom, t=top),
        hovermode="x",
        plot_bgcolor=bgcolor,
    )

    return go.FigureWidget(data=[pl_hist], layout=hist_layout) 
Example #6
Source File: analysis.py    From cryodrgn with GNU General Public License v3.0 4 votes vote down vote up
def ipy_plot_interactive_annotate(df, ind, opacity=.3):
    import plotly.graph_objs as go
    from ipywidgets import interactive
    if 'labels' in df.columns:
        text = [f'Class {k}: index {i}' for i,k in zip(df.index, df.labels)] # hovertext
    else:
        text = [f'index {i}' for i in df.index] # hovertext
    xaxis, yaxis = df.columns[0], df.columns[1]
    scatter = go.Scattergl(x=df[xaxis], 
                           y=df[yaxis], 
                           mode='markers',
                           text=text,
                           marker=dict(size=2,
                                       opacity=opacity,
                                       ))
    sub = df.loc[ind]
    text = [f'{k}){i}' for i,k in zip(sub.index, sub.labels)]
    scatter2 = go.Scatter(x=sub[xaxis],
                            y=sub[yaxis],
                            mode='markers+text',
                            text=text,
                            textposition="top center",
                            textfont=dict(size=9,color='black'),
                            marker=dict(size=5,color='black'))
    f = go.FigureWidget([scatter,scatter2])
    f.update_layout(xaxis_title=xaxis, yaxis_title=yaxis)
    
    def update_axes(xaxis, yaxis, color_by, colorscale):
        scatter = f.data[0]
        scatter.x = df[xaxis]
        scatter.y = df[yaxis]
        
        scatter.marker.colorscale = colorscale
        if colorscale is None:
            scatter.marker.color = None
        else:
            scatter.marker.color = df[color_by] if color_by != 'index' else df.index
    
        scatter2 = f.data[1]
        scatter2.x = sub[xaxis]
        scatter2.y = sub[yaxis]
        with f.batch_update(): # what is this for??
            f.layout.xaxis.title = xaxis
            f.layout.yaxis.title = yaxis
        
    widget = interactive(update_axes, 
                    yaxis = df.select_dtypes('number').columns, 
                    xaxis = df.select_dtypes('number').columns,
                    color_by = df.columns,
                    colorscale = [None,'hsv','plotly3','deep','portland','picnic','armyrose'])
    return widget, f 
Example #7
Source File: analysis.py    From cryodrgn with GNU General Public License v3.0 4 votes vote down vote up
def ipy_plot_interactive(df, opacity=.3):
    import plotly.graph_objs as go
    from ipywidgets import interactive
    if 'labels' in df.columns:
        text = [f'Class {k}: index {i}' for i,k in zip(df.index, df.labels)] # hovertext
    else:
        text = [f'index {i}' for i in df.index] # hovertext
    
    xaxis, yaxis = df.columns[0], df.columns[1]
    f = go.FigureWidget([go.Scattergl(x=df[xaxis],
                                  y=df[yaxis],
                                  mode='markers',
                                  text=text,
                                  marker=dict(size=2,
                                              opacity=opacity,
                                              color=np.arange(len(df)),
                                              colorscale='hsv'
                                             ))])
    scatter = f.data[0]
    N = len(df)
    f.update_layout(xaxis_title=xaxis, yaxis_title=yaxis)
    f.layout.dragmode = 'lasso'

    def update_axes(xaxis, yaxis, color_by, colorscale):
        scatter = f.data[0]
        scatter.x = df[xaxis]
        scatter.y = df[yaxis]
        
        scatter.marker.colorscale = colorscale
        if colorscale is None:
            scatter.marker.color = None
        else:
            scatter.marker.color = df[color_by] if color_by != 'index' else df.index
        with f.batch_update(): # what is this for??
            f.layout.xaxis.title = xaxis
            f.layout.yaxis.title = yaxis
 
    widget = interactive(update_axes, 
                         yaxis=df.select_dtypes('number').columns, 
                         xaxis=df.select_dtypes('number').columns,
                         color_by = df.columns,
                         colorscale = [None,'hsv','plotly3','deep','portland','picnic','armyrose'])

    t = go.FigureWidget([go.Table(
                        header=dict(values=['index']),
                        cells=dict(values=[df.index]),
                        )])

    def selection_fn(trace, points, selector):
        t.data[0].cells.values = [df.loc[points.point_inds].index]

    scatter.on_selection(selection_fn)
    return widget, f, t