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:

time,x,y,z,u,v,w,temperature
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 “plotly.express”
to generate an animation similar to what I aim
but with spheres (please, see code below):

import plotly.express 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
                    animation_frame='time',
                    color='temperature',
                    size = np.linalg.norm(df[['u','v','w']].values,axis=1),#norm of velocity
                    size_max=50, 
                    opacity=0.7,
                    color_continuous_scale=px.colors.sequential.Blues
)

fig.update_layout(
    scene = dict(
    xaxis = dict(nticks=4, range=[0,3]),
    yaxis = dict(nticks=4, range=[0,3]),
    zaxis = dict(nticks=4, range=[0,3]),
    aspectmode='manual',
    aspectratio=dict(x=1, y=1, z=1))
)

fig.show() #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 https://plot.ly/python/animations/#animated-figures-with-graph-objects. 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 https://github.com/plotly/plotly.js/issues/new. Unfortunately it’s unlikely to be a high-priority feature unless of course it can be sponsored, which would be great.