Black Lives Matter. Please consider donating to Black Girls Code today.

Cone/vector field animation and assigning a color to each cone by value other than its norm

Hello all, I am trying to use Plotly in Python
to create an animated (vector) cone field
where the color of each cone is specified
independently and not all vectors are persistent in time.
Allow me to elaborate.

For example, if I have a file ‘sampleVectors.csv’,
as follows:

0,    0,   0,   0,   1.1, 1.6, 1.4, 15.5
0,    1.1, 1.2, 1.3, 2.2, 2.4, 2.6, 13.0
0,    0.5, 0.7, 0.5, 1.5, 0.5, 1.0, 13.0
1,    1.0, 0.8, 1.2, 1.0, 1.2, 1.4, 12.5
2,    2.1, 2.3, 1.8, 2.2, 2.4, 2.6, 14.0
2,    1.8, 1.9, 2.0, 2.7, 2.3, 2.5, 14.2

I know I can use “scatter_3d” from “”
to generate an animation similar to what I aim
but with spheres (please, see code below):

import as px
import pandas as pd
import numpy as np

df = pd.read_csv('sampleVectors.csv')

fig = px.scatter_3d(df, x='x', y='y', z='z',
                    # u='u', v='v', w='w',    # <---- direction
                    size = np.linalg.norm(df[['u','v','w']].values,axis=1),#norm of velocity

    scene = dict(
    xaxis = dict(nticks=4, range=[0,3]),
    yaxis = dict(nticks=4, range=[0,3]),
    zaxis = dict(nticks=4, range=[0,3]),
    aspectratio=dict(x=1, y=1, z=1))
) #working offline

But I would ideally like (in order of importance):

  1. The markers to be cones with
    the direction of the cones given
    by ‘u’,‘v’,‘w’.
  2. The color to be specified for each cone via ‘temperature’.

I have not been able to find information
for “Cone” from “plotly.graph_objects”
either on how to make an animation or
on how to specify the color of each cone
independently. Even achieving either one
of those two items would be very helpful to me.

Thank you very much in advance.

Hi @Carlo, so

  1. there is not plotly express function for cones but you can still generate the animation manually, as described in It’s likely that a px.cone function will be added at some point but there is no timeline for this yet.
  2. unfortunately, it is not possible to pass an independent color array to cone as for scatter. You can open an issue on the tracker of the plotly.js library to discuss about adding such a feature Unfortunately it’s unlikely to be a high-priority feature unless of course it can be sponsored, which would be great.