本文整理汇总了Python中plotly.graph_objects.Figure方法的典型用法代码示例。如果您正苦于以下问题:Python graph_objects.Figure方法的具体用法?Python graph_objects.Figure怎么用?Python graph_objects.Figure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plotly.graph_objects
的用法示例。
在下文中一共展示了graph_objects.Figure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def __init__(self):
self.fig = go.Figure()
# Vertices of the faces
self.x_face = []
self.y_face = []
self.z_face = []
# Connectivity and color of the faces
self.i_face = []
self.j_face = []
self.k_face = []
self.intensity_face = []
# Vertices of the lines
self.x_line = []
self.y_line = []
self.z_line = []
# Vertices of the streamlines
self.x_streamline = []
self.y_streamline = []
self.z_streamline = []
示例2: plot
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def plot(self, **kwargs):
"""Plot stiffness coefficient vs frequency.
Parameters
----------
**kwargs : optional
Additional key word arguments can be passed to change the plot layout only
(e.g. width=1000, height=800, ...).
*See Plotly Python Figure Reference for more information.
Returns
-------
fig : Plotly graph_objects.Figure()
The figure object with the plot.
Example
-------
>>> bearing = bearing_example()
>>> fig = bearing.kxx.plot()
>>> # fig.show()
"""
fig = super().plot(**kwargs)
fig.update_yaxes(title_text="<b>Stiffness (N/m)</b>")
return fig
示例3: savefig
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def savefig(
self,
filename: str,
figsize: Tuple[Optional[int]] = (None, None),
scale: float = 1,
transparent: bool = False
) -> None:
"""Save the figure.
Args:
filename: Filename to save to.
figsize: Figure size (W x H) in pixels.
scale: Scale of the output figure.
transparent: Whether to use transparent background.
"""
if transparent:
plot_color = self._fig.layout['plot_bgcolor']
paper_color = self._fig.layout['paper_bgcolor']
self._fig.update_layout(paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)')
self._fig.write_image(filename, width=figsize[0], height=figsize[1], scale=scale)
if transparent:
self._fig.update_layout(plot_bgcolor=plot_color,
paper_bgcolor=paper_color)
示例4: make_chart
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def make_chart(title):
import json
import plotly.graph_objects as go
import plotly
layout = go.Layout(title=title)
data = go.Scatter(
x=[1, 2, 3, 4],
y=[10, 11, 12, 13],
mode="markers",
marker=dict(size=[40, 60, 80, 100], color=[0, 1, 2, 3]),
)
fig = go.Figure(data=data)
fig = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
layout = json.dumps(layout, cls=plotly.utils.PlotlyJSONEncoder)
return fig, layout
示例5: performance_plot
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def performance_plot(perf, title):
formats = ['nbformat'] + JUPYTEXT_FORMATS
mean = perf.groupby('implementation').mean().loc[formats]
std = perf.groupby('implementation').std().loc[formats]
data = [go.Bar(x=mean.index,
y=mean[col],
error_y=dict(
type='data',
array=std[col],
color=color,
thickness=0.5
) if col != 'size' else dict(),
name=col,
yaxis={'read': 'y1', 'write': 'y2', 'size': 'y3'}[col])
for col, color in zip(mean.columns, DEFAULT_PLOTLY_COLORS)]
layout = go.Layout(title=title,
xaxis=dict(title='Implementation', anchor='y3'),
yaxis=dict(domain=[0.7, 1], title='Read (secs)'),
yaxis2=dict(domain=[0.35, .65], title='Write (secs)'),
yaxis3=dict(domain=[0, .3], title='Size')
)
return go.Figure(data=data, layout=layout)
示例6: create_figure
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def create_figure(self):
f = go.Figure()
self._set_layout(f)
return f
示例7: init_fig
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def init_fig(self, fig, reward, done, timestamp):
if fig is None:
fig = go.Figure()
elif not isinstance(fig, self.type_fig_allowed):
raise PlotError("PlotPlotly cannot plot on figure of type {}. The accepted type is {}. You provided an "
"invalid argument for \"fig\"".format(type(fig), self.type_fig_allowed))
return fig
示例8: write_worker_log
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def write_worker_log(self, worker_logs: List[dict]):
"""Log the mean scores of each episode per update step to wandb."""
# NOTE: Worker plots are passed onto wandb.log as matplotlib.pyplot
# since wandb doesn't support logging multiple lines to single plot
if self.args.log:
self.set_wandb()
# Plot individual workers
fig = go.Figure()
worker_id = 0
for worker_log in worker_logs:
fig.add_trace(
go.Scatter(
x=list(worker_log.keys()),
y=smoothen_graph(list(worker_log.values())),
mode="lines",
name=f"Worker {worker_id}",
line=dict(width=2),
)
)
worker_id = worker_id + 1
# Plot mean scores
steps = worker_logs[0].keys()
mean_scores = []
for step in steps:
each_scores = [worker_log[step] for worker_log in worker_logs]
mean_scores.append(np.mean(each_scores))
fig.add_trace(
go.Scatter(
x=list(worker_logs[0].keys()),
y=mean_scores,
mode="lines+markers",
name="Mean scores",
line=dict(width=5),
)
)
# Write to wandb
wandb.log({"Worker scores": fig})
示例9: plot_score
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def plot_score(all_scores):
fig = go.Figure(data=go.Bar(y=all_scores))
fig.write_html('DQN_CNN_Trend_figure.html')
示例10: plot_score
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def plot_score(all_scores):
fig = go.Figure(data=go.Bar(y=all_scores))
fig.write_html('Trend_figure.html')
示例11: plot_rewards_over_trials
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def plot_rewards_over_trials(rewards, env_name, save=False):
import plotly.graph_objects as go
data = []
traces = []
colors = plt.get_cmap('tab10').colors
i = 0
cs_str = 'rgb' + str(colors[i])
ys = np.stack(rewards)
data.append(ys)
err_traces, xs, ys = generate_errorbar_traces(np.asarray(data[i]), color=cs_str, name=f"simulation")
for t in err_traces:
traces.append(t)
layout = dict(title=f"Learning Curve Reward vs Number of Trials (Env: {env_name})",
xaxis={'title': 'Trial Num'},
yaxis={'title': 'Cum. Reward'},
plot_bgcolor='white',
showlegend=False,
font=dict(family='Times New Roman', size=30, color='#7f7f7f'),
height=1000,
width=1500,
legend={'x': .83, 'y': .05, 'bgcolor': 'rgba(50, 50, 50, .03)'})
fig = {
'data': traces,
'layout': layout
}
fig = go.Figure(fig)
if save:
fig.write_image(os.getcwd() + "/learning.png")
else:
fig.show()
return fig
示例12: plot_learning
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def plot_learning(exp, cfg):
objective_means = np.array([[exp.trials[trial].objective_mean] for trial in exp.trials])
cumulative = optimization_trace_single_method(
y=np.maximum.accumulate(objective_means.T, axis=1), ylabel=cfg.metric.name,
trace_color=(83, 78, 194),
# optimum=-3.32237, # Known minimum objective for Hartmann6 function.
)
all = optimization_trace_single_method(
y=objective_means.T, ylabel=cfg.metric.name,
model_transitions=[cfg.bo.random], trace_color=(114, 110, 180),
# optimum=-3.32237, # Known minimum objective for Hartmann6 function.
)
layout_learn = cumulative[0]['layout']
layout_learn['paper_bgcolor'] = 'rgba(0,0,0,0)'
layout_learn['plot_bgcolor'] = 'rgba(0,0,0,0)'
d1 = cumulative[0]['data']
d2 = all[0]['data']
for t in d1:
t['legendgroup'] = cfg.metric.name + ", cum. max"
if 'name' in t and t['name'] == 'Generator change':
t['name'] = 'End Random Iterations'
else:
t['name'] = cfg.metric.name + ", cum. max"
for t in d2:
t['legendgroup'] = cfg.metric.name
if 'name' in t and t['name'] == 'Generator change':
t['name'] = 'End Random Iterations'
else:
t['name'] = cfg.metric.name
fig = {
"data": d1 + d2, # data,
"layout": layout_learn,
}
import plotly.graph_objects as go
return go.Figure(fig)
示例13: test_plots
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def test_plots():
bearing = fluid_flow_short_numerical()
bearing.calculate_pressure_matrix_numerical()
figure_type = type(go.Figure())
assert isinstance(plot_shape(bearing), figure_type)
assert isinstance(plot_eccentricity(bearing), figure_type)
assert isinstance(plot_pressure_theta(bearing), figure_type)
assert isinstance(plot_pressure_z(bearing), figure_type)
assert isinstance(plot_pressure_theta_cylindrical(bearing), figure_type)
assert isinstance(plot_pressure_surface(bearing), figure_type)
示例14: __init__
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def __init__(self, fig: go.Figure):
"""PlotlyFigure class.
Args:
fig: Figure to use.
"""
self._fig = fig
示例15: build_box_subplots
# 需要导入模块: from plotly import graph_objects [as 别名]
# 或者: from plotly.graph_objects import Figure [as 别名]
def build_box_subplots(stat: pd.DataFrame) -> go.Figure:
"""Create a figure with box subplots showing fields coverages for jobs.
Args:
stat: a dataframe with field coverages
Returns:
A figure with box subplots
"""
stat = stat.drop(columns=["std", "mean", "target deviation"])
traces = [
go.Box(
y=row[1],
name=row[0],
boxpoints="all",
jitter=0.3,
boxmean="sd",
hoverinfo="y",
)
for row in stat.iterrows()
]
cols = 4
rows = math.ceil(len(stat) / cols)
fig = make_subplots(rows=rows, cols=cols)
x = 0
for i, j in itertools.product(range(1, rows + 1), range(1, cols + 1)):
if x == len(traces):
break
fig.append_trace(traces[x], i, j)
x += 1
fig.update_layout(height=rows * 300 + 200, width=cols * 300, showlegend=False)
fig.update_yaxes(tickformat=".4p")
return fig