本文整理汇总了Python中plotly.graph_objs.Box方法的典型用法代码示例。如果您正苦于以下问题:Python graph_objs.Box方法的具体用法?Python graph_objs.Box怎么用?Python graph_objs.Box使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plotly.graph_objs
的用法示例。
在下文中一共展示了graph_objs.Box方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_trace
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import Box [as 别名]
def create_trace(settings):
# flip the variables according to the box orientation
if settings.properties['box_orientation'] == 'h':
y = settings.x
x = settings.y
else:
x = settings.x
y = settings.y
return [graph_objs.Box(
x=x or None,
y=y,
name=settings.data_defined_legend_title if settings.data_defined_legend_title != '' else settings.properties['name'],
customdata=settings.properties['custom'],
boxmean=settings.properties['box_stat'],
orientation=settings.properties['box_orientation'],
boxpoints=settings.properties['box_outliers'],
fillcolor=settings.data_defined_colors[0] if settings.data_defined_colors else settings.properties['in_color'],
line={'color': settings.data_defined_stroke_colors[0] if settings.data_defined_stroke_colors else settings.properties['out_color'],
'width': settings.data_defined_stroke_widths[0] if settings.data_defined_stroke_widths else settings.properties['marker_width']},
opacity=settings.properties['opacity']
)]
示例2: calc_graph
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import Box [as 别名]
def calc_graph(self):
# main data about technologies
data = self.process_individual_ramping_capacity()
hours = data.index.hour
graph = []
for field in self.analysis_fields:
y = data[field].values / 1E6 # into MW
trace = go.Box(x=hours, y=y, name=NAMING[field], marker=dict(color=COLOR[field]))
graph.append(trace)
return graph
示例3: name
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import Box [as 别名]
def name():
return PlotType.tr('Box Plot')
示例4: plot_ngenes
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import Box [as 别名]
def plot_ngenes(input_gffs, outdir):
# get simplified file names
file_names = [
os.path.splitext(os.path.basename(gff))[0] for gff in input_gffs
]
# count genes
ngenes = np.zeros(len(input_gffs))
for i, gff_file in enumerate(input_gffs):
with open(gff_file, 'r') as gff:
for line in gff:
if "##FASTA" in line: break
if "##" == line[:2]: continue
if "CDS" not in line: continue
ngenes[i] += 1
with open(outdir + "ngenes.txt", "w") as genes_out:
genes_out.write("sample\tno_genes\n")
for i, j in zip(file_names, ngenes):
genes_out.write("%s\t%s\n" % (i, j))
# generate static plot
plt.style.use('ggplot')
fig = plt.figure()
plt.barh(np.arange(len(ngenes)), ngenes)
plt.yticks(np.arange(len(ngenes)), file_names)
plt.grid(True)
plt.ylabel("File Name")
plt.xlabel("Number of Genes")
plt.tight_layout()
fig.savefig(outdir + "ngenes_barplot.png")
# generate interactive boxplot
data = [
go.Box(y=ngenes,
text=file_names,
hoverinfo="text",
boxpoints='all',
jitter=0.3,
pointpos=-1.8)
]
layout = go.Layout(autosize=True,
xaxis=dict(title='',
titlefont=dict(size=18, color='black'),
showticklabels=False,
automargin=True),
yaxis=dict(title="Number of Genes",
titlefont=dict(size=18, color='black'),
showticklabels=True,
tickfont=dict(size=10, color='black')))
fig = go.Figure(data=data, layout=layout)
offline.plot(fig, filename=outdir + "ngenes_boxplot.html", auto_open=False)
return
示例5: plot_ncontigs
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import Box [as 别名]
def plot_ncontigs(input_gffs, outdir):
# get simplified file names
file_names = [
os.path.splitext(os.path.basename(gff))[0] for gff in input_gffs
]
# count genes
ncontigs = np.zeros(len(input_gffs))
for i, gff_file in enumerate(input_gffs):
with open(gff_file, 'r') as gff:
in_fasta = False
for line in gff:
if in_fasta and (line[0] == ">"):
ncontigs[i] += 1
if "##FASTA" in line:
in_fasta = True
# generate static plot
with open(outdir + "ncontigs.txt", "w") as contig_out:
contig_out.write("sample\tno_contigs\n")
for i, j in zip(file_names, ncontigs):
contig_out.write("%s\t%s\n" % (i, j))
plt.style.use('ggplot')
fig = plt.figure()
plt.barh(np.arange(len(ncontigs)), ncontigs)
plt.yticks(np.arange(len(ncontigs)), file_names)
plt.grid(True)
plt.ylabel("File Name")
plt.xlabel("Number of Contigs")
plt.tight_layout()
fig.savefig(outdir + "ncontigs_barplot.png")
# generate interactive boxplot
data = [
go.Box(y=ncontigs,
text=file_names,
hoverinfo="text",
boxpoints='all',
jitter=0.3,
pointpos=-1.8)
]
layout = go.Layout(autosize=True,
xaxis=dict(title='',
titlefont=dict(size=18, color='black'),
showticklabels=False,
automargin=True),
yaxis=dict(title="Number of Contigs",
titlefont=dict(size=18, color='black'),
showticklabels=True,
tickfont=dict(size=10, color='black')))
fig = go.Figure(data=data, layout=layout)
offline.plot(fig,
filename=outdir + "ncontigs_boxplot.html",
auto_open=False)
return
示例6: fig_boxplot_msglen
# 需要导入模块: from plotly import graph_objs [as 别名]
# 或者: from plotly.graph_objs import Box [as 别名]
def fig_boxplot_msglen(df, username_to_color=None, title="", xlabel=None):
"""Visualize boxplot.
Args:
df (pandas.DataFrame): Chat data.
username_to_color (dict, optional). Dictionary mapping username to color. Defaults to None.
title (str, optional): Title for plot. Defaults to "".
xlabel (str, optional): x-axis label title. Defaults to None.
Returns:
plotly.graph_objs.Figure
"""
df = df.copy()
# Get message lengths
df[COLNAMES_DF.MESSAGE_LENGTH] = df[COLNAMES_DF.MESSAGE].apply(lambda x: len(x))
# Sort users by median
user_stats = df.groupby(COLNAMES_DF.USERNAME)\
.aggregate({COLNAMES_DF.MESSAGE_LENGTH: 'median'})[COLNAMES_DF.MESSAGE_LENGTH].sort_values(ascending=False)
# Create a list of traces
data = []
for username in user_stats.index:
x = df[df[COLNAMES_DF.USERNAME] == username][COLNAMES_DF.MESSAGE_LENGTH]
trace = go.Box(
y=x.values,
showlegend=True,
name=username,
boxpoints='outliers',
marker_color=username_to_color[username] if username_to_color else None
)
data.append(trace)
layout = dict(
title=title,
xaxis=dict(title=xlabel)
)
fig = go.Figure(data=data, layout=layout)
return fig