本文整理汇总了Python中plotly.graph_objs.FigureWidget方法的典型用法代码示例。如果您正苦于以下问题:Python graph_objs.FigureWidget方法的具体用法?Python graph_objs.FigureWidget怎么用?Python graph_objs.FigureWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plotly.graph_objs
的用法示例。
在下文中一共展示了graph_objs.FigureWidget方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import FigureWidget [as 别名]
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)
示例2: summary_fig
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import FigureWidget [as 别名]
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)
示例3: createContent
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import FigureWidget [as 别名]
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
示例4: node_hist_fig
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import FigureWidget [as 别名]
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)
示例5: ipy_plot_interactive_annotate
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import FigureWidget [as 别名]
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
示例6: ipy_plot_interactive
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import FigureWidget [as 别名]
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