2

属性的文档字符串sizerefplotly.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}}")

请注意,您必须首先从我的 repoanimation_opts中删除kwarg 或使用 plotly,因为官方版本还不支持 animation_opts(请参阅我在此处提出的问题)。

上面代码产生的图(还没想出如何转换成视频格式!)

这个系数是在哪里计算的?我已经搜索了代码,但一无所获。提前致谢!

PS是的,我包含了很多无关的信息。我从未在 plotly 中看到过 3d 圆锥动画的示例,所以我想提供一个,并且我在 plotly.py 中处理了动画界面,这肯定对某人有用!

编辑:在 github 上看到这个问题

4

1 回答 1

0

发现 Plotly.js 中有一个内部比例因子导致了这种混乱。我已经在我当前的 plotly 回购版本中修复了这个问题

于 2019-04-12T17:48:53.083 回答