我使用以下 Python 代码来生成旭日图:-
import plotly
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv('CellUsageStats.csv',dtype={'Population':int},keep_default_na=False)
print(df.head(50))
fig = px.sunburst(df, path=['LibPrefix', 'MasterPrefixAbrHead', 'MasterPrefixAbrTail', 'Drive'], values='Population', color='Population', color_continuous_scale=px.colors.sequential.Inferno)
fig.update_traces(hovertemplate='Pattern: %{currentPath}%{label}<br>Matches: %{value}<br>Percent of <b>%{parent}</b>: %{percentParent:0.2%f}<br>Percent of <b>%{entry}</b>: %{percentEntry:0.2%f}<br>Percent of <b>%{root}</b>: %{percentRoot:0.2%f}')
fig.show()
plotly.offline.plot(fig, filename='sunburst.html')
Run Code Online (Sandbox Code Playgroud)
我有第二个 csv 文件,使用上面相同的代码来生成另一个旭日。如何将它们组合起来在同一个 html 输出中创建并排绘图?我发现...
https://plotly.com/python/sunburst-charts/
但是,我确实需要 px.sunburst 属性,并且上面链接中的示例使用 go.Sunburst,而不是 px.sunburst。是否有一种直接的方法可以从两组不同的数据生成并排图?
谢谢!
我在 Heroku 上构建一个 Web 应用程序并遇到了这个问题:
2020-10-24T03:56:57.857273+00:00 app[web.1]: You can now view your Streamlit app in your browser.
2020-10-24T03:56:57.857320+00:00 app[web.1]:
2020-10-24T03:56:57.857675+00:00 app[web.1]: Network URL: http://172.17.131.6:8501
2020-10-24T03:56:57.857819+00:00 app[web.1]: External URL: http://34.202.9.122:8501
2020-10-24T03:56:57.857932+00:00 app[web.1]:
2020-10-24T03:56:59.458188+00:00 app[web.1]: 2020-10-24 03:56:59.458 Generating new fontManager, this may take some time...
2020-10-24T03:57:41.000000+00:00 app[api]: Build succeeded
2020-10-24T03:57:52.127634+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-10-24T03:57:52.147741+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-10-24T03:57:52.252583+00:00 heroku[web.1]: Process exited with status 137
2020-10-24T03:57:52.301275+00:00 …Run Code Online (Sandbox Code Playgroud) 我正在使用 R 编程语言。我正在尝试学习如何在图表上叠加点,然后将它们可视化。
使用以下代码,我可以生成一些时间序列数据,按月聚合它们,取平均值/最小值/最大值,并绘制以下图表:
library(xts)
library(ggplot2)
library(dplyr)
library(plotly)
library(lubridate)
set.seed(123)
#time series 1
date_decision_made = seq(as.Date("2014/1/1"), as.Date("2016/1/1"),by="day")
property_damages_in_dollars <- rnorm(731,100,10)
final_data <- data.frame(date_decision_made, property_damages_in_dollars)
#####aggregate
final_data$year_month <- format(as.Date(final_data$date_decision_made), "%Y-%m")
final_data$year_month <- as.factor(final_data$year_month)
f = final_data %>% group_by (year_month) %>% summarise(max_value = max(property_damages_in_dollars), mean_value = mean(property_damages_in_dollars), min_value = min(property_damages_in_dollars))
####plot####
fig <- plot_ly(f, x = ~year_month, y = ~max_value, type = 'scatter', mode = 'lines',
line = list(color = 'transparent'),
showlegend = FALSE, name = 'max_value')
fig <- fig %>% add_trace(y …Run Code Online (Sandbox Code Playgroud) 下面是一些代码的示例,其中名称出现在悬停信息标签的外部。
在我的实际代码中,我已经考虑了悬停信息中的名称,所以我只想让这一点消失(请参见下图中突出显示的部分)。
不幸的是,我无法设置name ="",因为我正在使用名称值来更改标记的颜色。
有谁能帮忙解决这个问题,或者以前有过尝试这样做的经验吗?任何帮助将不胜感激。
这很奇怪,因为这在本页的plotly dash 官方文档中显示发生了。
category = "a"
from plotly.subplots import make_subplots
fig_ex = make_subplots(rows=1, cols=2)
fig_ex.add_scatter(y=[4, 2, 3.5], mode="markers",
marker=dict(size=20, color="MediumPurple"),
name="a", row=1, col=1)
fig_ex.add_bar(y=[2, 1, 3],
marker=dict(color="MediumPurple"),
name="b", row=1, col=1)
fig_ex.add_scatter(y=[2, 3.5, 4], mode="markers",
marker=dict(size=20, color="MediumPurple"),
name="c", row=1, col=2)
fig_ex.add_bar(y=[1, 3, 2],
marker=dict(color="MediumPurple"),
name="d", row=1, col=2)
fig_ex.update_layout(showlegend = False)
fig_ex.update_traces(hovertemplate =
"x: %{x}<br>" +
"y: %{y}")
fig_ex.for_each_trace(
lambda trace: trace.update(marker_color="LightSeaGreen") if trace.name == category else (),
)
fig_ex.show()
Run Code Online (Sandbox Code Playgroud)
帖子Plotly:在折线图中最后一个值处注释标记 显示了如何使用文本和单个标记注释行尾。但是,如何对多行执行相同的操作,同时设置关联的文本和标记以匹配所有行的颜色?
# imports
import pandas as pd
import plotly.express as px
# data
df = px.data.stocks()
colors = px.colors.qualitative.T10
# plotly
fig = px.line(df,
x = 'date',
y = [c for c in df.columns if c != 'date'],
template = 'plotly_dark',
color_discrete_sequence = colors,
title = 'Stocks',
)
fig.show()
Run Code Online (Sandbox Code Playgroud) 我正在使用绘图go.Indicator来显示数据集的某些值。这是我的代码:
import dash_core_components as dcc
import plotly.graph_objects as go
value = dff.shape[0]
fig = go.Figure()
fig.add_trace(go.Indicator(
mode="number",
value=value,
domain={'row': 0, 'column': 0},
title='Total number of incidences'
)
fig.update_layout(
paper_bgcolor ='lightgray',
grid={
'rows': 1,
'columns': 1,
'pattern': 'independent'
}
)
dcc.Graph(
id='indicator-incidences',
figure=fig
)
Run Code Online (Sandbox Code Playgroud)
和这里
就是图中所表示的。正如您所看到的,它扩展到页面的总宽度,并且高度大于必要的高度。
如何实现图形根据其包含的指示器调整大小?
我正在尝试将 Plotly Dash 仪表板组织成列的部分,但我无法理解我在这里做错了什么。我已将我的组件包含在一个 dbc.Row 内的单独 dbc.Cols 中,并指定了我希望它们占用的列的宽度,但所有内容都只是堆叠在一起。理想情况下,我会将卡片单独放在左侧的一栏中,然后将问题放在右侧。有人可以帮我诊断我正在做的事情导致我的所有组件堆叠吗?
#Import packages
import dash
import dash_core_components as dcc
import dash_bootstrap_components as dbc
import dash_html_components as html
from dash.dependencies import Input, Output, State
app = dash.Dash()
#App Layout
app.layout = html.Div([
dbc.Row(children=[
dbc.Col(id="card_col",width = 6),
dbc.Col(id="form", width=6, children=[
html.Div([
dbc.FormGroup(children=[
dbc.Label("Question 1"),
dbc.Col(
dcc.Input(type="text", id="q1", placeholder="Enter your info"),
width=6
)
],row=True)
]),
html.Br(),
html.Div(children=[
dbc.FormGroup(children=[
dbc.Label("Question 2?"),
dbc.Col(
dbc.Input(type="text",id="q2",placeholder="Enter your info"),
width=6
)
],row=True)
]),
html.Br(),
html.Div([
dbc.FormGroup(children=[
dbc.Label("Yes/No?"),
dbc.Col(
dbc.RadioItems(id="q3",options=[{"label": "Yes", "value": …Run Code Online (Sandbox Code Playgroud) 我最近将 package.json 中的依赖项升级到最新版本。依赖项已过时至少 2 年或更长时间。我正在处理的网站显示各种类型的图形和图表,并且在升级到 package.json 之前工作正常。这会是什么原因呢?
这是更新后的 package.json
{
"name": "pipeline-viewer",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^12.0.0",
"@angular/cdk": "^12.0.0",
"@angular/common": "^12.0.0",
"@angular/compiler": "^12.0.0",
"@angular/core": "^12.0.0",
"@angular/flex-layout": "^12.0.0-beta.35",
"@angular/forms": "^12.0.0",
"@angular/material": "^12.0.0",
"@angular/material-moment-adapter": "^12.0.0",
"@angular/platform-browser": "^12.0.0",
"@angular/platform-browser-dynamic": "^12.0.0",
"@angular/router": "^12.0.0",
"@wizpanda/super-gif": "0.0.5",
"angular-plotly.js": "^4.0.4",
"bootstrap": "^5.1.3",
"moment": "^2.29.1",
"plotly.js": "^2.5.1",
"rxjs": "^7.4.0",
"rxjs-compat": "^6.6.7",
"zone.js": "^0.11.4"
},
"devDependencies": …Run Code Online (Sandbox Code Playgroud) 我需要一条穿过该图原点的对角线
类似于 ggplot2 的东西geom_abline(intercept = 0 , slope = 1)
,但是对于 R 中的plotly
library(plotly)
fig <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)
fig
Run Code Online (Sandbox Code Playgroud)