我已经在 plotly 上做了这个图
我想删除空白,只显示有值的 x,并隐藏没有任何值的 x
我该怎么做?
这是我的代码:
go.Bar(name=i,x=listeDepartement,y=listePPA))
fig = go.Figure(data=bar)
fig.update_layout(barmode='stack')
fig.write_html('histogram.html',auto_open=True)
fig.show()
Run Code Online (Sandbox Code Playgroud) 目标:我以前从未这样做过,并且是 Python 的新手。我想在按下按钮时随时运行 python 脚本。
问题:有人可以指出如何解决这个问题吗?
我的代码:
**Button HTML**
# Layout of Dash App HTML
app.layout = html.Div(
children=[
html.Div(
html.Button('Detect', id='button'),
html.Div(id='output-container-button',
children='Hit the button to update.')
],
),
],
)
@app.callback(
dash.dependencies.Output('output-container-button', 'children'),
[dash.dependencies.Input('button')])
def run_script_onClick():
return os.system('python /Users/ME/Desktop/DSP_Frontend/Pipeline/Pipeline_Dynamic.py')
Run Code Online (Sandbox Code Playgroud)
目前这给出了错误:
Traceback (most recent call last):
File "app.py", line 592, in <module>
[dash.dependencies.Input('button')])
TypeError: __init__() missing 1 required positional argument: 'component_property'
Run Code Online (Sandbox Code Playgroud)
编辑:
我认为解决方案可能是将 some_argument 添加到 run_script_onClick 中:
def run_script_onClick(some_argument):
return os.system('python /Users/ME/Desktop/DSP_Frontend/Pipeline/Pipeline_Dynamic.py')
Run Code Online (Sandbox Code Playgroud)
我目前正在浏览此列表以查找合适的 item() …
我想使用 plot.ly 来绘制虹膜数据集。它在分散数据中有一个颜色参数,就像 seabron 中的色调一样,但它只改变标记的颜色而不能改变文本的颜色,我找不到任何改变每组颜色的标记类型的原因。代码是:
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", text='sepal_width')
fig.update_traces(textposition='top center', textfont_size=14, textfont_color=c)
fig.show()
Run Code Online (Sandbox Code Playgroud)
我希望文本颜色像每个点的颜色和 3 种不同类型的标记,2 种类型的 bc。
我有许多可变长度的二维序列,即列表列表,其中每个子列表都是一个序列。我想在 3d 可视化中投影这些序列/行/子列表,将时间步长作为另一个维度。到目前为止,我未能使用plotly.express.
import plotly.express as px
t = [[ii+1 for ii in range(len(features[i]))] for i in range(len(labels))]
x0 = [[x[0] for x in features[i]] for i in range(len(labels))]
x1 = [[x[1] for x in features[i]] for i in range(len(labels))]
df = pd.DataFrame(dict(
X=[tii for ti in t for tii in ti],
Y=[xii for xi in x0 for xii in xi],
Z=[xii for xi in x1 for xii in xi],
color=[aa for a in labels for aa in …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Dash 显示数据框。我拥有的数据框是https://www.kaggle.com/timoboz/superbowl-history-1967-2020。我的目标是通过一个搜索按钮在网页上显示数据框,该按钮可动态搜索所有列并过滤数据框。
到目前为止,我有以下显示数据框的代码。
import pandas as pd
import dash
import dash_table
from dash.dependencies import Input, Output
df = pd.read_csv('./Data/superbowl.csv')
PAGE_SIZE = 10
app = dash.Dash(__name__)
app.layout = dash_table.DataTable(
id='datatable-paging',
columns=[
{"name": i, "id": i} for i in df.columns #sorted(df.columns)
],
page_current=0,
page_size=PAGE_SIZE,
page_action='custom',
sort_action='custom',
sort_mode='single',
sort_by=[]
)
@app.callback(
Output('datatable-paging', 'data'),
[Input('datatable-paging', "page_current"),
Input('datatable-paging', "page_size"),
Input('datatable-paging', 'sort_by')])
def update_table(page_current,page_size,sort_by):
if len(sort_by):
dff = df.sort_values(
sort_by[0]['column_id'],
ascending=sort_by[0]['direction'] == 'asc',
inplace=False
)
else:
# No sort is applied
dff = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Plotly 中的 Dash 构建一个仪表板,该仪表板由一系列图块(文本)组成,如下图所示。
我正在尝试构建一个组件以重用它并构建下面的布局。每个框将包含一个标题、一个值和一个描述,如下所示。
有可用的组件吗?有人可以帮助我了解任何基本的想法/代码吗?
提前致谢!
信息“trace0”始终显示在蓝线的悬停文本框旁边,如何将其删除?为什么不在橙色线上?trace0 究竟是什么意思?
library(plotly)
fig <- plot_ly()
fig <- fig %>%
add_trace(
type = 'scatter',
mode = 'lines+markers',
x = c(1,2,3,4,5),
y = c(2.02825,1.63728,6.83839,4.8485,4.73463),
text = c("Text A", "Text B", "Text C", "Text D", "Text E"),
hovertemplate = paste('<i>Price</i>: $%{y:.2f}',
'<br><b>X</b>: %{x}<br>',
'<b>%{text}</b>'),
showlegend = FALSE
)
fig <- fig %>%
add_trace(
type = 'scatter',
mode = 'lines+markers',
x = c(1,2,3,4,5),
y = c(3.02825,2.63728,4.83839,3.8485,1.73463),
hovertemplate = 'Price: %{y:$.2f}<extra></extra>',
showlegend = FALSE
)
fig
Run Code Online (Sandbox Code Playgroud)
提前致谢!
statewise_cases["Country"] = "Country"
print(statewise_cases)
fig = px.treemap(statewise_cases, path = ['Country', 'State'], values='Deaths')
fig.show()
Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码使用 plotly express line 显示时间序列数据。
fig = px.line(df, x="date", y="close", color="type" ,category_orders = co ,color_discrete_sequence = colors,
line_group="type", title = company)
fig.update_layout(height=500, width=1500)#hovermode="x unified"
fig.show()
Run Code Online (Sandbox Code Playgroud)
但是在悬停时的绘图中,它以以下格式显示日期:“月,年”,即它不显示日期。但我希望以以下格式显示日期:“月日,年”。
我有以下脚本将 Pandas 数据框转换为带有 Plotly 的交互式 html 表:
goals_output_df = pd.read_csv(os.path.join(question_dir, "data/output.csv"))
fig = go.Figure(data=[go.Table(
columnwidth = [15,170,15,35,35],
header=dict(values=['<b>' + x + '</b>' for x in list(goals_output_df.columns)],
# fill_color='#b9e2ff',
line_color='darkslategray',
align='center',
font=dict(color='black', family="Lato", size=20),
height=30
),
cells=dict(values=[goals_output_df[column] for column in goals_output_df.columns],
# fill_color='#e6f2fd',
line_color='darkslategray',
align='left',
font=dict(color='black', family="Lato", size=20),
height=30
))
])
fig.update_layout(
title="<b>Output summary for %s</b>"%question.strip('question'),
font=dict(
family="Lato",
size=18,
color="#000000"))
fig.write_html(os.path.join(question_dir, "results/output.html"))
Run Code Online (Sandbox Code Playgroud)
该表包含一个名为“Output”的列,每行可以具有三个值之一:“YES”、“NO”和“BORDERLINE”。
我希望能够更改“输出”列中文本的颜色,使“是”为绿色,“否”为红色,“边界线”为蓝色。
知道我怎么做吗?Plotly 文档似乎没有帮助。