具有可变动画速度的 3d 动画圆锥图中圆锥体的大小
Size of cones in 3d animated cone plot with variable animation speed
属性 sizeref
in plotly.graph_objs._cone.py
的文档字符串说:
Adjusts the cone size scaling. The size of the cones is
determined by their u/v/w norm multiplied a factor and
`sizeref`. This factor (computed internally) corresponds to the
minimum "time" to travel across two successive x/y/z positions
at the average velocity of those two successive positions. All
cones in a given trace use the same factor. With `sizemode` set
to "scaled", `sizeref` is unitless, its default value is 0.5
With `sizemode` set to "absolute", `sizeref` has the same units
as the u/v/w vector field, its the default value is half the
sample's maximum vector norm.
The 'sizeref' property is a number and may be specified as:
- An int or float in the interval [0, inf]
Returns
-------
int|float
哪里有计算出这个神秘的因素,但我终究找不到它实际计算出的地方。由于我不明白这个奇怪的因素是如何计算的,所以我的动画中出现了非常奇怪的行为,如下所示:
import numpy as np
import plotly.graph_objs as go
import plotly.offline as pl
###np.around used because plotly.js doesn't like full precision float64s
t = np.linspace(0,2*np.pi,100)
x = np.around(np.vstack((np.cos(t), np.cos(t+np.pi))),decimals=6)
y = np.around(np.vstack((np.sin(t), np.sin(t+np.pi))),decimals=6)
z = np.around(np.vstack((np.ones(len(t)),np.ones(len(t)))),decimals=6)
v = np.around(np.vstack((np.cos(t), np.cos(t+np.pi))),decimals=6)
u = np.around(-np.vstack((np.sin(t), np.sin(t+np.pi))),decimals=6)
w = np.around(np.vstack((np.zeros(len(t)),np.ones(len(t)))),decimals=6)
fig3=go.Figure([dict(anchor="cm",showscale=False,sizemode="scaled",type="cone",x=x[:,0],y=y[:,0]
,z=z[:,0]
,u=u[:,0],v=v[:,0]
,w=w[:,0])],layout=go.Layout(
scene=dict(aspectratio=dict(x=1,y=1,z=0.25),
xaxis=dict(range=[-2,2], tickmode="linear"),
yaxis=dict(range=[-2,2], tickmode="linear"),
zaxis=dict(range=[0,5]))))
fig3.frames= [go.Frame(data=[dict(type="cone",x=x[:,i],y=y[:,i],z=z[:,i],u=u[:,i],v=v[:,i],w=w[:,i])],
layout=go.Layout(annotations=[dict(text="frame {}".format(i))]))for i in np.array(range(len(t)))]
pl.plot(fig3, animation_opts="{frame: {duration: 1}}")
请注意,您必须先删除 animation_opts
kwarg 或使用 my repo since the official version doesn't support animation_opts yet (see the issue I raised here 中的 plotly。
这个系数是在哪里计算的?我已经搜索了代码,但一无所获。
提前致谢!
P.S 是的,我包含了很多无关的信息。我从来没有在 plotly 中看到过 3d 圆锥动画的例子,所以我想提供一个,我在 plotly.py 中研究了动画界面,这对某些人肯定有用!
编辑:看这个issue on github
发现 Plotly.js 中有一个内部缩放因子导致了这个混乱。我已经在我当前的 plotly here.
回购版本中修复了这个问题
属性 sizeref
in plotly.graph_objs._cone.py
的文档字符串说:
Adjusts the cone size scaling. The size of the cones is
determined by their u/v/w norm multiplied a factor and
`sizeref`. This factor (computed internally) corresponds to the
minimum "time" to travel across two successive x/y/z positions
at the average velocity of those two successive positions. All
cones in a given trace use the same factor. With `sizemode` set
to "scaled", `sizeref` is unitless, its default value is 0.5
With `sizemode` set to "absolute", `sizeref` has the same units
as the u/v/w vector field, its the default value is half the
sample's maximum vector norm.
The 'sizeref' property is a number and may be specified as:
- An int or float in the interval [0, inf]
Returns
-------
int|float
哪里有计算出这个神秘的因素,但我终究找不到它实际计算出的地方。由于我不明白这个奇怪的因素是如何计算的,所以我的动画中出现了非常奇怪的行为,如下所示:
import numpy as np
import plotly.graph_objs as go
import plotly.offline as pl
###np.around used because plotly.js doesn't like full precision float64s
t = np.linspace(0,2*np.pi,100)
x = np.around(np.vstack((np.cos(t), np.cos(t+np.pi))),decimals=6)
y = np.around(np.vstack((np.sin(t), np.sin(t+np.pi))),decimals=6)
z = np.around(np.vstack((np.ones(len(t)),np.ones(len(t)))),decimals=6)
v = np.around(np.vstack((np.cos(t), np.cos(t+np.pi))),decimals=6)
u = np.around(-np.vstack((np.sin(t), np.sin(t+np.pi))),decimals=6)
w = np.around(np.vstack((np.zeros(len(t)),np.ones(len(t)))),decimals=6)
fig3=go.Figure([dict(anchor="cm",showscale=False,sizemode="scaled",type="cone",x=x[:,0],y=y[:,0]
,z=z[:,0]
,u=u[:,0],v=v[:,0]
,w=w[:,0])],layout=go.Layout(
scene=dict(aspectratio=dict(x=1,y=1,z=0.25),
xaxis=dict(range=[-2,2], tickmode="linear"),
yaxis=dict(range=[-2,2], tickmode="linear"),
zaxis=dict(range=[0,5]))))
fig3.frames= [go.Frame(data=[dict(type="cone",x=x[:,i],y=y[:,i],z=z[:,i],u=u[:,i],v=v[:,i],w=w[:,i])],
layout=go.Layout(annotations=[dict(text="frame {}".format(i))]))for i in np.array(range(len(t)))]
pl.plot(fig3, animation_opts="{frame: {duration: 1}}")
请注意,您必须先删除 animation_opts
kwarg 或使用 my repo since the official version doesn't support animation_opts yet (see the issue I raised here 中的 plotly。
这个系数是在哪里计算的?我已经搜索了代码,但一无所获。 提前致谢!
P.S 是的,我包含了很多无关的信息。我从来没有在 plotly 中看到过 3d 圆锥动画的例子,所以我想提供一个,我在 plotly.py 中研究了动画界面,这对某些人肯定有用!
编辑:看这个issue on github
发现 Plotly.js 中有一个内部缩放因子导致了这个混乱。我已经在我当前的 plotly here.
回购版本中修复了这个问题