Hi everyone! I have a problem with the matching colors between traces.
Making only auto colors I have a plot like this, i.e in each sufrace I have different lines, markers and mesh.
I want the same plot, i.e. different colors of each surface, but the same colors for all traces(line, marker, mesh) inside of one surface. Like this (this one is from matplotlib):
My code with autocolors looks like:
colors = plt.cm.rainbow(np.linspace(0, 1, len(phases)))
fig = go.Figure()
for polyhedra, points, col in zip(phases, groups, colors):
hull = scipy.spatial.ConvexHull(polyhedra)
polyhedra_points = hull.vertices.tolist()
faces = hull.simplices
polyhedra_coordinates = polyhedra[polyhedra_points]
tri_vertices= polyhedra[faces]
Xe = []
Ye = []
Ze = []
for T in tri_vertices:
Xe += [T[k%3][0] for k in range(4)]+[ None]
Ye += [T[k%3][1] for k in range(4)]+[ None]
Ze += [T[k%3][2] for k in range(4)]+[ None]
#define the trace consisting in all triangle edges
lines= go.Scatter3d(
x=Xe,
y=Ye,
z=Ze,
mode='lines',
name = points,
line=dict(width=3)) #, color= col
fig.add_trace(lines)
sub_df = result_fin[result_fin.prototype==points]
fig.add_trace(go.Scatter3d(x=sub_df.Teta_N, y=sub_df.Teta_V, z=sub_df.Teta_chi,
text = result_fin.composition, #if I want to see all compositions
mode='markers',
marker=dict(size = 2), #color = col,
name = points
)
)
fig.add_trace(go.Mesh3d(x=polyhedra_coordinates[:, 0],
y=polyhedra_coordinates[:, 1],
z=polyhedra_coordinates[:, 2],
#text = polyhedra_df.composition, #we see only the names of the polyhedra points
#color = col, #find out how to set color
name = points,
contour = dict(show = True, width = 10),#color = 'red',
opacity = .4,
alphahull = 0
),
)
# Update all traces together
fig.update_traces(showlegend=True)
fig.update_layout(width = 1000, height = 1000,
#colorway = default,
title="Structural 3D map",
legend_title='Phase name',
scene=dict(
xaxis = dict(title=r'Theta_N', nticks=10, range=[-1,1]),
yaxis = dict(title=r'Theta_V', nticks=10, range=[-1,1]),
zaxis = dict(title=r'Theta_chi', nticks=10, range=[-1,1]))
)
fig.show()
I put all color settings in comments because it doesnβt work if I try to set them (with zip function).
As I understood, I need to set the list of colors, but when I try it, it always gets me some error about the wrong type of input data for colors.
Does somebody know how to deal with this?