本文整理汇总了Python中plotly.tools.make_subplots方法的典型用法代码示例。如果您正苦于以下问题:Python tools.make_subplots方法的具体用法?Python tools.make_subplots怎么用?Python tools.make_subplots使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plotly.tools
的用法示例。
在下文中一共展示了tools.make_subplots方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: renderIfExhausted
# 需要导入模块: from plotly import tools [as 别名]
# 或者: from plotly.tools import make_subplots [as 别名]
def renderIfExhausted(self):
if not self.isExhausted():
return False
fig = tools.make_subplots(self.rows, self.cols, subplot_titles=tuple(f.title for f in self.figures), print_grid=False)
row = 1
col = 1
n = 1
for f in self.figures:
for trace in f.getScatterGOs():
fig.append_trace(trace, row, col)
if f.logx:
fig['layout']['xaxis'+str(n)]['type'] = 'log'
fig['layout']['xaxis'+str(n)]['autorange'] = True
if f.logy:
fig['layout']['yaxis'+str(n)]['type'] = 'log'
fig['layout']['yaxis'+str(n)]['autorange'] = True
col += 1
n += 1
if col > self.cols:
col = 1
row += 1
if row > self.rows:
row = self.rows
plotly.offline.iplot(fig)
return True
示例2: plot_experiment
# 需要导入模块: from plotly import tools [as 别名]
# 或者: from plotly.tools import make_subplots [as 别名]
def plot_experiment(experiment_spec, experiment_df, metrics_cols):
'''
Plot the metrics vs. specs parameters of an experiment, where each point is a trial.
ref colors: https://plot.ly/python/heatmaps-contours-and-2dhistograms-tutorial/#plotlys-predefined-color-scales
'''
y_cols = metrics_cols
x_cols = ps.difference(experiment_df.columns.tolist(), y_cols)
fig = tools.make_subplots(rows=len(y_cols), cols=len(x_cols), shared_xaxes=True, shared_yaxes=True, print_grid=False)
strength_sr = experiment_df['strength']
min_strength = strength_sr.values.min()
max_strength = strength_sr.values.max()
for row_idx, y in enumerate(y_cols):
for col_idx, x in enumerate(x_cols):
x_sr = experiment_df[x]
guard_cat_x = x_sr.astype(str) if x_sr.dtype == 'object' else x_sr
trace = go.Scatter(
y=experiment_df[y], yaxis=f'y{row_idx+1}',
x=guard_cat_x, xaxis=f'x{col_idx+1}',
showlegend=False, mode='markers',
marker={
'symbol': 'circle-open-dot', 'color': experiment_df['strength'], 'opacity': 0.5,
# dump first quarter of colorscale that is too bright
'cmin': min_strength - 0.50 * (max_strength - min_strength), 'cmax': max_strength,
'colorscale': 'YlGnBu', 'reversescale': True
},
)
fig.add_trace(trace, row_idx + 1, col_idx + 1)
fig.layout[f'xaxis{col_idx+1}'].update(title='<br>'.join(ps.chunk(x, 20)), zerolinewidth=1, categoryarray=sorted(guard_cat_x.unique()))
fig.layout[f'yaxis{row_idx+1}'].update(title=y, rangemode='tozero')
fig.layout.update(
title=f'experiment graph: {experiment_spec["name"]}',
width=100 + 300 * len(x_cols), height=200 + 300 * len(y_cols))
plot(fig)
graph_prepath = experiment_spec['meta']['graph_prepath']
save_image(fig, f'{graph_prepath}_experiment_graph.png')
# save important graphs in prepath directly
prepath = experiment_spec['meta']['prepath']
save_image(fig, f'{prepath}_experiment_graph.png')
return fig
示例3: plot_metrics
# 需要导入模块: from plotly import tools [as 别名]
# 或者: from plotly.tools import make_subplots [as 别名]
def plot_metrics(self):
"""For plotting"""
metric_traces = defaultdict(list)
for loss_name, loss_dict in self.evolution.items():
for split_name, vals in loss_dict.items():
trace = go.Scatter(
x=list(vals.keys()),
y=list(vals.values()),
mode="lines",
name=split_name,
)
metric_traces[loss_name].append(trace)
metric_names = list(metric_traces.keys())
fig = pytools.make_subplots(
rows=1, cols=len(metric_traces), subplot_titles=tuple(metric_names)
)
for metric_idx, metric_name in enumerate(metric_names):
traces = metric_traces[metric_name]
for trace in traces:
fig.append_trace(trace, 1, metric_idx + 1)
plotly_path = os.path.join(self.checkpoint, "plotly.html")
py.plot(fig, filename=plotly_path, auto_open=False)
if self.hosting_folder is not None:
hosted_plotly_path = os.path.join(self.hosting_folder, "plotly.html")
py.plot(fig, filename=hosted_plotly_path, auto_open=False)
示例4: Plot_Storages
# 需要导入模块: from plotly import tools [as 别名]
# 或者: from plotly.tools import make_subplots [as 别名]
def Plot_Storages(self, StoragePath, PathFigure):
'''Hace un plot del storage en el periodo de simulacion'''
#Lee los datos
Data = pd.read_csv(StoragePath, skiprows=4, index_col=6, parse_dates=True)
#Hace la figura
fig = tools.make_subplots(rows=5, cols=1)
for c,key in enumerate(Data.columns.values[1:].tolist()):
trace1 = go.Scatter(
x = Data.index.to_pydatetime(),
y = Data[key].values,
name = key,
line = {'width':3},
fill='tozeroy',
)
fig.append_trace(trace1, c+1, 1)
fig['layout'].update(height=600, width=600,
showlegend = False,
yaxis=dict(title='Estado [mm]',),
margin=dict(
l=50,
r=50,
b=50,
t=50,
pad=4
))
plot(fig,filename=PathFigure, auto_open = False)
示例5: get_figure
# 需要导入模块: from plotly import tools [as 别名]
# 或者: from plotly.tools import make_subplots [as 别名]
def get_figure(self):
from pandas import MultiIndex
layout = dict(legend=dict(x=0.7, y=1), margin=dict(r=0, t=40))
is_3d = isinstance(self.table.index, MultiIndex)
if is_3d:
import plotly.graph_objs as go
from plotly import tools
cols = self.table.columns
ncols = 2 if len(cols) > 1 else 1
nrows = len(cols) / ncols + len(cols) % ncols
fig = tools.make_subplots(
rows=nrows, cols=ncols, subplot_titles=cols, print_grid=False
)
for idx, col in enumerate(cols):
series = self.table[col]
z = [s.tolist() for _, s in series.groupby(level=0)]
fig.append_trace(
go.Heatmap(z=z, showscale=False), idx / ncols + 1, idx % ncols + 1
)
fig["layout"].update(layout)
else:
xaxis = self.config.get("x", self.table.columns[0])
yaxis = self.config.get("y", None)
yaxes = (
[yaxis]
if yaxis is not None
else [col for col in self.table.columns if col != xaxis]
)
traces = []
for axis in yaxes:
if "ₑᵣᵣ" not in axis:
tbl = self.table[[xaxis, axis]].replace("", np.nan).dropna()
traces.append(
dict(x=tbl[xaxis].tolist(), y=tbl[axis].tolist(), name=axis)
)
for trace in traces:
err_axis = trace["name"] + "ₑᵣᵣ"
if err_axis in yaxes:
errors = self.table[err_axis].replace("", np.nan).dropna()
trace["error_y"] = dict(type="data", array=errors, visible=True)
trace["mode"] = "markers"
layout.update(
dict(
xaxis=dict(title=xaxis),
yaxis=dict(
title=self.config.get("ytitle"),
type=self.config.get("yaxis", {}).get("type", "-"),
),
showlegend=self.config.get("showlegend", True),
)
)
fig = dict(data=traces, layout=layout)
return fig
示例6: build_sub_plots
# 需要导入模块: from plotly import tools [as 别名]
# 或者: from plotly.tools import make_subplots [as 别名]
def build_sub_plots(self, grid, row, column, ptrace): # pylint:disable=too-many-arguments
"""
Draws plot in different plot canvases (not overlapping)
params:
grid (string): 'row' or 'col'. Plot are created in rows or columns
row (int): number of rows (if row is selected)
column (int): number of columns (if column is selected)
ptrace (list of Plot Traces): list of all the different Plot Traces
:return: the final html path containing the plot with the js_string for
the interaction
Console usage:
.. code-block:: python
# create the initial object
settings = PlotSettings(plot_type, plot_properties, layout_properties)
factory = PlotFactory(settings)
# finally create the Figures
path_to_output = factory.build_sub_plots('row', 1, gr, pl, tt)
"""
if grid == 'row':
fig = tools.make_subplots(rows=row, cols=column)
for i, itm in enumerate(ptrace):
fig.append_trace(itm, row, i + 1)
elif grid == 'col':
fig = tools.make_subplots(rows=row, cols=column)
for i, itm in enumerate(ptrace):
fig.append_trace(itm, i + 1, column)
# set some configurations
config = {'scrollZoom': True, 'editable': True}
# first lines of additional html with the link to the local javascript
self.raw_plot = '<head><meta charset="utf-8" /><script src="{}"></script>' \
'<script src="{}"></script></head>'.format(
self.POLY_FILL_PATH, self.PLOTLY_PATH)
# call the plot method without all the javascript code
self.raw_plot += plotly.offline.plot(fig, output_type='div', include_plotlyjs=False, show_link=False,
config=config)
# insert callback for javascript events
self.raw_plot += self.js_callback(self.raw_plot)
# use regex to replace the string ReplaceTheDiv with the correct plot id generated by plotly
match = re.search(r'Plotly.newPlot\(\s*[\'"](.+?)[\'"]', self.raw_plot)
substr = match.group(1)
self.raw_plot = self.raw_plot.replace('ReplaceTheDiv', substr)
self.plot_path = os.path.join(tempfile.gettempdir(), 'temp_plot_name.html')
with open(self.plot_path, "w") as f:
f.write(self.raw_plot)
return self.plot_path