I am having a small issue when plotting cones with Plotly. In my data, I have 2 types of vectors for norm 1 and 1.5. When I plot just 8 of them on a cube, the colors are rendered very well with each type of vector have one of two colors. But as soon as I go bigger with 2 cubes for example then it becomes quite random. Here is a minimal example that reproduces this issue.
The data:
import numpy as np
import pandas as pd
import plotly.graph_objects as go
pos=pd.DataFrame([
[0.0,0.0,0.0],
[0.5,0.0,0.0],
[0.0, 0.5,0.0],
[0.5,0.5,0.0],
[0.0,0.0,0.5],
[0.5,0.0,0.5],
[0.0,0.5,0.5],
[0.5,0.5,0.5]
], columns=['x','y','z'])
pos2=pd.DataFrame([
[0.0,0.0,0.0],
[0.5,0.0,0.0],
[0.0, 0.5,0.0],
[0.5,0.5,0.0],
[0.0,0.0,0.5],
[0.5,0.0,0.5],
[0.0,0.5,0.5],
[0.5,0.5,0.5],
[1.0,0.0,0.0],
[1.5,0.0,0.0],
[1.0, 0.5,0.0],
[1.5,0.5,0.0],
[1.0,0.0,0.5],
[1.5,0.0,0.5],
[1.0,0.5,0.5],
[1.5,0.5,0.5]
], columns=['x','y','z'])
type = pd.DataFrame(np.array([[1],[1.5],[1],[1.5],[1],[1.5],[1],[1.5],[1],[1.5],[1],[1.5],[1],[1.5],[1],[1.5]]), columns=['Type'])
vec = pd.DataFrame(np.array([[ 0.56493151, 0.58643612, -0.5804697 ],
[ 0.52637789, -0.81556709, -0.24036772],
[-0.64603163, -0.4828808 , 0.59115925],
[-0.42559098, 0.83496509, 0.34886332],
[ 0.16788166, 0.63197593, 0.75658587],
[ 0.8961372 , -0.20426566, 0.39397165],
[-0.08599516, -0.68074558, -0.72745467],
[-0.90366508, 0.25896575, -0.34106622],
[ 0.68002417, 0.47929612, -0.55483543],
[ 0.2721998 , 0.70224966, -0.65783941],
[-0.68464335, -0.51281615, 0.5179605 ],
[-0.35330142, -0.53106658, 0.77015998],
[-0.46760187, 0.29858559, 0.83198265],
[ 0.68459979, -0.50165276, 0.52883612],
[ 0.44722097, -0.32492581, -0.83331664],
[-0.55474541, 0.49785322, -0.66663311]]), columns=['x','y','z'])
Plotting 1 cube:
layout = go.Layout(
title='Cones',
width=700,
height=700
)
fig = go.Figure(data = go.Cone(
x=pos['x'],
y=pos['y'],
z=pos['z'],
u=type['Type']*vec['x'],
v=type['Type']*vec['y'],
w=type['Type']*vec['z'],
colorscale='viridis',
colorbar=dict(thickness=20, ticklen=4),
sizemode="absolute",
sizeref=0.5,
anchor='tail'
), layout=layout)
fig
The figure displays the correct color for the 8 vectors.
Plotting 2 cubes:
layout = go.Layout(
title='Cones',
width=700,
height=700
)
fig = go.Figure(data = go.Cone(
x=pos.append(pos+[1,0,0], ignore_index=True)['x'],
y=pos.append(pos+[1,0,0], ignore_index=True)['y'],
z=pos.append(pos+[1,0,0], ignore_index=True)['z'],
u=type['Type']*vec['x'],
v=type['Type']*vec['y'],
w=type['Type']*vec['z'],
colorscale='viridis',
colorbar=dict(thickness=20, ticklen=4),
sizemode="absolute",
sizeref=0.5,
anchor='tail'
), layout=layout)
fig
As you can see on this last image, all vectors of norm 1 are dark purple, whereas the vectors of norm 1.5 take a gradient of colors with some even being dark purple as shown by the cone that has its coordinates displayed.
Does anyone know how to solve this issue?



