I’m working with Plotly’s go.Cone function to visualize 3D data. In my plot, I’m representing cones with positions (x, y, z) and directions (u, v, w), where the components u, v, and w correspond to forces in each direction. Currently, the color bar in the plot is based on the total magnitude of the force vectors (sqrt(u^2 + v^2 + w^2)) by default.
However, since I normalize the forces to keep the cones the same size, this default color scale is not suitable as all values end up being less than or equal to 1. What I would like is for the color bar to reflect only the values from a specific column in the DataFrame that I use, and not the combined magnitude. In other words, I want each cone to be colored according to a pre-calculated value in the DataFrame at its position, without considering the default magnitude.
I normalized the forces because previously there were issues with magnitude, resulting in few large cones and many too small, as shown in Figure 1:
fig1enter image description here
The resulting image using normalized data is shown below:
fig2 enter image description here
Here’s the code I’m using:
fig = go.Figure(data=go.Cone(
x=df[“x”], y=df[“y”], z=df[“z”],
u=df[“Force_x”]/df[“Force_Mag”], v=df[“Force_y”]/df[“Force_Mag”], w=df[“Force_z”]/df[“Force_Mag”],
colorscale=‘Viridis’, colorbar=dict(title=‘Force Mag’),
hovertext=df[“Aminoacido”], # text for info
hoverinfo=“x+y+z+text+norm”,
sizemode=“absolute”, sizeref=10, # cone size
fig.show()
))
The DataFrame already has the magnitude in df[“Force_Mag”], which is the column I would like to use for coloring and for setting the color bar. I have tried several approaches without success. Is there a way to achieve this with go.Cone to achieve this type of visualization?
Thanks in advance for any help!
try to use something like:
color=df[‘force_mag’]
but it is not compatible, I was hoping to add a colormap other than the default one plotly uses in go.cone
Willy Menacho Nacho is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.