我希望图表中不仅仅有一条 3d 线,以便能够比较数据,不幸的是,这种.add_方法并不适用于所有类型的图。
fig = px.line_3d(sample, x='Time', y='y' ,z='intensity')
# fig.add_line_3d(sample2, x='Time', y='y' ,z='intensity')
fig
Run Code Online (Sandbox Code Playgroud)
我可以从图形中提取痕迹,然后以某种方式将它们全部绘制在一起吗?
我需要用 R 绘制饼图,但我不想显示百分比,而是希望将原始计数覆盖在饼图部分上(即 300、250、110、190)。
下面的代码制作饼图,但带有百分比。
WhatIHave <- c("Money" = 300,
"Dinosaurs" = 250,
"Aether" = 110,
"Discussions" = 190)
data <- data.frame("Category" = names(WhatIHave), WhatIHave)
p <- plot_ly(data, labels = ~Category, values = ~WhatIHave, type = 'pie') %>%
layout(title = 'Lovely Pie',
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
p
Run Code Online (Sandbox Code Playgroud)
我不敢相信以前没有人问过这个问题,但我确实在之前的问题或情节文档中找不到它。如果这是一个重复的问题,我们深表歉意。
然而,当我生成图表时,这条线并没有结束,我尝试了很多方法,但没有任何效果。
r 中有什么,是我用已经定义的值声明的一些变量
fig = go.Figure()
fig.add_trace(go.Scatterpolar(
name = "Ideal",
r=[ ideal_Funciones_Responsabilidades, ideal_etapas_propias, ideal_Aspectos_Legales, ideal_Gestion_Ambiental, ideal_Gestion_de_Seguridad,
ideal_manejo_Informacion, hallado_Tecnicos, ideal_Humanos , ideal_transversales],
theta=categories,
#connectgaps=True,
#line_color = 'darkviolet'
type= 'scatterpolar',
mode = 'lines',
))
fig.add_trace(go.Scatterpolar(
name = "Hallado",
r=[ hallado_Funciones_Responsabilidades, hallado_etapas_propias, hallado_Aspectos_Legales, hallado_Gestion_Ambiental, hallado_Gestion_de_Seguridad,
hallado_manejo_Informacion, hallado_Tecnicos, hallado_Humanos, hallado_transversales],
theta=categories,
#mode = "markers",
type= 'scatterpolar',
mode = 'lines',
#line_color = 'peru'
))
fig.update_layout(
polar=dict(
radialaxis=dict(
#visible=True,
range=[0, maximo_valor + 1]
)
),
#line_close=True,
# showlegend=False
)
Run Code Online (Sandbox Code Playgroud)
我将关注您对这个主题的帮助。
我正在尝试使用 Databricks 中的 Plotly 库渲染图表。但是,没有渲染任何图像。我用这个语句为例:
from plotly.offline import init_notebook_mode, iplot
from plotly import graph_objs as go
# Initialize plotly
init_notebook_mode(connected=True)
daily_df=df
def plotly_df(df, title=''):
"""Visualize all the dataframe columns as line plots."""
common_kw = dict(x=df.index, mode='lines')
data = [go.Scatter(y=df[c], name=c, **common_kw) for c in df.columns]
layout = dict(title=title)
fig = dict(data=data, layout=layout)
iplot(fig, show_link=False)
plotly_df(daily_df)
Run Code Online (Sandbox Code Playgroud)
没有输出。为什么?
我在 csv 文件中有一些数据集(总共 3 个),需要以不同的方式表示它。它们必然是带有 kde(核密度估计)的折线图、箱线图和直方图。
我知道如何单独绘制它们,但为了更方便,我需要将它们合并到一个输出中。在查阅参考资料后,我确实编写了一些代码,但它没有运行。
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import plotly.figure_factory as ff
import numpy as np
y1 = np.random.randn(200) - 1
y2 = np.random.randn(200)
y3 = np.random.randn(200) + 1
x = np.linspace(0, 1, 200)
fig = make_subplots(
rows=3, cols=2,
column_widths=[0.6, 0.4],
row_heights=[0.3, 0.6],
specs=[[{"type": "scatter"}, {"type": "box"}],
[{"type": "scatter"}, {"type": "dist", "rowspan": 2}]
[{"type": "scatter"}, None ]])
fig.add_trace(
go.Scatter(x = x,
y = y1,
hoverinfo = 'x+y',
mode='lines',
line=dict(color='rgb(0, 0, 0)',
width=1),
showlegend=False, …Run Code Online (Sandbox Code Playgroud) 我想绘制一些代表不同物质质量流量的桑基图以供报告。我想用图例来区分这些物质,但我不知道该怎么做。我尝试过showlegend但没有成功
import plotly.graph_objects as go
fig = go.Figure(data=[go.Sankey(
node = dict(
pad = 15,
thickness = 20,
line = dict(color = "black", width = 0.5),
label = ['household','industry','waste'],
color = "blue"
),
link = dict(
source = [0,1,0,1], # indices correspond to labels, eg A1, A2, A2, B1, ...
target = [2,2,2,2],
value = [7190,2074,4483,74.50],
label = ['aluminium','aluminium','copper','copper'],
color = ['#d7d6d6','#d7d6d6','#f3cf07','#f3cf07']
))])
fig.update_layout(showlegend=True)
fig.show()
Run Code Online (Sandbox Code Playgroud)
我为什么想知道?
这似乎是一个非常简单的问题,但我在使用下拉菜单编辑具有多个轨迹的图形时遇到了一些困难,所以我真的很渴望确保我理解plotlys下拉菜单、更新菜单和按钮的内部工作原理100%正确。因此,如果有人能抽出时间来看看下面的示例,那就太好了。
问题是什么?
考虑由下面的代码片段生成的以下简单绘图:
情节1:
代码1:
# imports
import plotly.graph_objs as go
import pandas as pd
import numpy as np
# data
df1 = pd.DataFrame({'index': ['1','2','3'], 'A': [10,10,12], 'B': [11,11,11]})
df2 = pd.DataFrame({'index': ['1','2','3'], 'A': [10,10,10], 'B': [11,11,12]})
# plotly figure setup
fig=go.Figure()
fig.add_trace(go.Scatter(x=df1['index'], y=df1['A'], mode='lines'))
fig.add_trace(go.Scatter(x=df1['index'], y=df1['B'], mode='lines'))
#f=fig.to_dict()
fig.show()
Run Code Online (Sandbox Code Playgroud)
现在我想用 替换蓝线的数据,df1['A']=[10,10,12]同时用df2['A']=[10,10,10]替换红线的数据。df1['B']=[11,11,11]df1['B']=[11,11,11]
我可以通过引入如下下拉菜单轻松地做到这一点:
图 2 - 下拉菜单 = df1:
图 3 - 下拉菜单 =df2
代码 2 - 与代码 1 相同,但添加了菜单:
# …Run Code Online (Sandbox Code Playgroud) 这是 Plotly 的后续问题:Plotly:更新菜单的按钮如何真正工作?
考虑由下面的代码片段生成的下图:
阴谋:
代码:
# imports
import plotly.graph_objs as go
import pandas as pd
import numpy as np
# data
df1 = pd.DataFrame({'index': ['1','2','3'], 'A': [10,10,12], 'B': [11,11,11]})
df2 = pd.DataFrame({'index': ['1','2','3'], 'A': [10,10,10], 'B': [11,11,12]})
# plotly figure setup
fig=go.Figure()
fig.add_trace(go.Scatter(x=df1['index'], y=df1['A'], mode='lines'))
fig.add_trace(go.Scatter(x=df1['index'], y=df1['B'], mode='lines'))
f=fig.to_dict()
#fig.show()
buttons=list([dict(args=[{'y':[df1['A'],df1['B']]}],
label="df1",
method="restyle"
),
dict(args=[{'y':[df2['A'], df2['B']]}],
label="df2",
method="restyle"
)
])
fig.update_layout(
updatemenus=[
go.layout.Updatemenu(
buttons=buttons,
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=-0.25,
xanchor="left",
y=1,
yanchor="top"
),
]
)
fig.show() …Run Code Online (Sandbox Code Playgroud) 我想用 R 中的绘图来表示以原点为根的 2D 向量。此外,我想根据分类变量为向量着色。问题是我可以创建颜色编码但没有箭头的线条:
library(plotly)
library(dplyr)
v <- c(1, 1)
b1 <- c(1, 0)
b2 <- c(0, 1)
df <- data.frame(
x = c(v[1], b1[1], b2[1]),
y = c(v[2], b1[2], b2[2]),
is_basis = c(FALSE, TRUE, TRUE)
)
df %>%
plot_ly(x = ~x, y = ~y, color = ~is_basis) %>%
add_segments(xend = ~x, yend = ~y, x = 0, y = 0, colors = c("red","black"))
Run Code Online (Sandbox Code Playgroud)
或者使用箭头但不使用颜色编码:
df %>%
plot_ly(x = ~x, y = ~y, color = ~is_basis) %>%
add_annotations(x = …Run Code Online (Sandbox Code Playgroud) 我试图在和四个显示为子图的甘特图中添加相同的标题。然而我在网上发现,这只显示了第一个图表上的标题,而不是全部。我已经找到了一些关于 R 的答案,但是任何关于 python 的帮助都会很棒x-axesy-axesfigs.update_layout()
figs = make_subplots(
rows=2, cols=2,
shared_xaxes=False,
subplot_titles =('Plot 1', 'PLot 2', 'PLot 3', 'Plot 4')
)
figs.update_layout(
title="Plot Title",
xaxis_title="Miliseconds",
yaxis_title="Services",
)
for trace in fig_operable.data:
figs.add_trace(trace, row=1, col=1)
for trace in fig_dynamic.data:
figs.add_trace(trace, row=2, col=1)
for trace in fig_early.data:
figs.add_trace(trace, row=1, col=2)
for trace in fig_hmi.data:
figs.add_trace(trace, row=2, col=2)
figs.update_layout(showlegend=False, title_text="Title of charts")
figs.show()
Run Code Online (Sandbox Code Playgroud) plotly ×10
python ×6
python-3.x ×2
r ×2
arrows ×1
axes ×1
databricks ×1
django ×1
gantt-chart ×1
matplotlib ×1
python-3.6 ×1
vector ×1