我正在尝试使用浮点数组创建 3D 曲面图。我尝试了可用的答案,但没有成功。
我的代码:
ydata xdata zdata
0 667.029710 38.666953 2156.370026
1 673.518030 38.578639 2167.733673
2 928.285970 39.558060 2984.315454
3 947.973966 39.329530 3065.414025
4 904.826638 40.241960 3071.355114
5 901.673720 40.259228 2947.752668
6 910.980404 41.478425 2906.467214
7 916.008852 41.813555 2933.900440
8 913.971114 41.583315 2955.543549
9 933.040692 42.577816 2979.264288
import plotly.graph_objects as go
import plotly.graph_objs
import pandas as pd
import numpy as np
xdata = df['xdata'].values
ydata = df['ydata'].values
zdata = df['zdata'].values
plotly.offline.plot({"data":[go.Surface(z=zdata, x=xdata, y=ydata)],
"layout":plotly.graph_objs.Layout(title='Some data', autosize=False,
width=500, height=500,
margin=dict(l=65, r=50, …Run Code Online (Sandbox Code Playgroud) 我使用 React 版本的plot.ly 来渲染 3D 散点图,但每次重新渲染组件时,该图都会重置为其默认配置。
如何防止这种情况发生并保持缩放/旋转配置?
下面是一个最小的代码示例。重申一下,如何保存缩放和旋转,以及如何在绘图上设置它?
setPlotData() {
const points = {
1: {x: 1, y: 1, z: 1},
2: {x: 2, y: 1, z: 1},
3: {x: 3, y: 2, z: 1}
}
const x=[], y=[], z=[]
Object.keys(points).forEach((key, index) => {
x.push(points[key].x); y.push(points[key].y); z.push(points[key].z)
})
const data1 = {
x: x, y: y, z: z,
mode: "markers",
marker: {
color: "rgb(16, 52, 166)",
size: 4,
symbol: "circle",
opacity: 1
},
type: "scatter3d"
}
this.setState({
scatterPlotData: [data1]
}) …Run Code Online (Sandbox Code Playgroud) 我正在制作一个折线图,其中包含大量在超高分辨率下运行的数据。在添加第二个 y 轴时,我发现,plotly svg 组件内的图表右侧会出现一个空白区域。当我关闭第二个轴时,那个空白空间就会消失。当图表在整个屏幕上最大化时,可以清楚地看到。
作为展示,我使用了plotly文档中的一个例子:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
# Add traces
fig.add_trace(
go.Scatter(x=[1, 2, 3], y=[40, 50, 60], name="yaxis data"),
secondary_y=False,
)
fig.add_trace(
go.Scatter(x=[2, 3, 4], y=[4, 5, 6], name="yaxis2 data"),
secondary_y=True,
)
# Add figure title
fig.update_layout(
title="Right margin",
showlegend=False
)
# Set x-axis title
fig.update_xaxes(title_text="xaxis title")
# Set y-axes titles
fig.update_yaxes(title_text="<b>primary</b> yaxis title", secondary_y=False)
fig.update_yaxes(title_text="<b>secondary</b> yaxis title", secondary_y=True)
fig.show()
Run Code Online (Sandbox Code Playgroud)
它产生以下图表,不再居中:
我怎样才能摆脱那个空白空间?
X = np.random.randn(100, 90)
import plotly.graph_objects as go
fig = go.Figure(data=[go.Surface(z=X)])
fig.update_layout(title='something', autosize=False,
width=500, height=500,
margin=dict(l=65, r=50, b=65, t=90))
fig.show()
Run Code Online (Sandbox Code Playgroud)
尝试了各种方法,但轴标签没有改变。他们只是说“x”和“y”。
我目前正在使用plotlyexpress 来创建Sunburst 图表。然而,我意识到孩子们的标称值是按字母顺序排列的。特别是对于绘制非常不幸的月份......你知道如何处理这个问题吗?也许是财产或某种解决方法?下面有一个例子,你可以自己尝试一下。提前致谢!
import plotly.express as px
import pandas as pd
import calendar
months = [x for x in calendar.month_name if x]
#Create Dataframe
data = []
for m in months:
data.append(['2018', m, 2])
df = pd.DataFrame(data, columns=['Year', 'Month', 'Value'])
#Compute Sunburst
fig = px.sunburst(df, path=['Year', 'Month'], values='Value')
fig.show()
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用plotly 绘制甘特图。重要的是水平泳道可以有多个在时间上分开的条。
我找到了一个使用日历日期 (YYYY-MM-DD) 的示例,并尝试使用时间 (HH:MM:SS) 进行转换。但是当我使用时间戳时,所有内容都会聚集在一起,没有间隙。
import plotly.express as px
import pandas as pd
df = pd.DataFrame([
dict(Start='00:01:12', Finish='00:01:59', Resource="Alex"),
dict(Start='00:04:51', Finish='00:05:28', Resource="Alex"),
dict(Start='00:02:12', Finish='00:04:34', Resource="Max")
])
fig = px.timeline(df, x_start="Start", x_end="Finish", y="Resource", color="Resource"
)
fig.update_layout(xaxis=dict(
title='Timestamp',
tickformat = '%H:%M:%S',
))
fig.show()
Run Code Online (Sandbox Code Playgroud)
桑基斯巧妙地填满了所有可用空间。
如果某些“分支”有 3 个级别(节点 0 -> 节点 1 -> 节点 3),而其他“分支”只有两个级别(节点 0 -> 节点 2),则最终节点(节点 2和节点 3)垂直向右对齐。
我希望能够垂直对齐Node 1(不是Node 3!)和Node 2,如附件中的第二个图所示。
对我来说,以编程方式对齐所有节点是相当困难的,所以我想避免这种可能性。
即使在前一种情况下,也会出现问题(Jupyter Lab 的代码):
import plotly.graph_objects as go
sources = [ 0, 0, 1, 1]
targets = [ 1, 2, 3, 4]
values = [59, 30, 29, 30]
labels = ['Node 0', 'Node 1', 'Node 2', 'Node 3', 'Node 4']
link = dict(source=sources, target=targets, value=values) …Run Code Online (Sandbox Code Playgroud) 我想准备一个子图,其中每个方面都是一个变量相对于其他变量的单独的双 y 轴图。因此,我制作了一个基本图p并在循环中添加辅助 y 轴变量:
library(rlang)
library(plotly)
library(tibble)
dual_axis_lines <- function(data, x, y_left, ..., facets = FALSE, axes = NULL){
x <- rlang::enquo(x)
y_left <- rlang::enquo(y_left)
y_right <- rlang::enquos(...)
y_left_axparms <- list(
title = FALSE,
tickfont = list(color = "#1f77b4"),
side = "left")
y_right_axparms <- list(
title = FALSE,
overlaying = "y",
side = "right",
zeroline = FALSE)
p <- plotly::plot_ly(data , x = x) %>%
plotly::add_trace(y = y_left, name = quo_name(y_left),
yaxis = "y1", type = 'scatter', …Run Code Online (Sandbox Code Playgroud) 我试图在 Plotly 中突出显示时间段。我似乎最好的方法是使用 Shapes,就像这样,但在现实世界中,您不想像示例 url 中那样手动添加每个形状。我认为 for 循环是最好的解决方案,但欢迎其他(计算量较小的)建议。
我的脚本如下所示:
np.random.seed(12345)
rows = 20
x = pd.Series(np.random.randn(rows),index=pd.date_range('1/1/2020', periods=rows)).cumsum()
df = pd.DataFrame({"index": x})
# add column showing what to shade
df["signal"] = df['index'] < 5
# plot index and highlight periods with Rectangle Shapes in Plotly
fig = px.line(df, x=df.index, y="index")
for row in df.iterrows():
if df['signal'] == False:
ply_shapes['shape_' + str(i)]=go.layout.Shape(type="rect",
x0=df.dato[i-1],
y0=0,
x1=df.dato[i],
y1=2000,
opacity=0.5,
layer="below"
)
lst_shapes=list(ply_shapes.values())
fig.update_layout(shapes=lst_shapes)
fig.show()
Run Code Online (Sandbox Code Playgroud)
但这返回:
ValueError: The truth value of a Series …Run Code Online (Sandbox Code Playgroud) 我很难让传奇在情节上变得更大。我已经用尽了文档、论坛、github 问题,但一无所获。开始思考情节并不是什么伟大的软件。
我创建了这个图表:
我想使试用版 1、试用版 2 和试用版 3 的图例中的线条变大。我可以使用他们的 api 将字体变大,但我没有看到对图例行的引用,现在想知道它是否可能。
这是一些代码:
fig.update_layout(
title_text="Dipole Moment X (0 V/nm)",
title_font=dict(size=44, family='Arial'),
template='simple_white',
xaxis_tickformat = 'i',
bargap=0.2, # gap between bars of adjacent location coordinates,
legend=dict(
orientation="h",
yanchor="bottom",
y=1.02,
xanchor="right",
x=1,
font = dict(family = "Arial", size = 60),
bordercolor="LightSteelBlue",
borderwidth=2,
itemsizing='trace'
),
legend_title = dict(font = dict(family = "Arial", size = 60)),
)
Run Code Online (Sandbox Code Playgroud)
玩弄了物品大小,也一无所获。有人知道如何实现这一目标吗?
更新:
根据下面的答案,我能够使线条变粗,但有一个限制。附上我认为的厚度极限(不知道确切尺寸)
plotly ×10
python ×6
plotly-dash ×2
gantt-chart ×1
legend ×1
matplotlib ×1
pandas ×1
plotly.js ×1
r ×1
r-plotly ×1
reactjs ×1
timestamp ×1