I am stuck I have to remove the legend from the plotly volume plot. The only reason for doing this is I am making a poster where I have bunch of similar figures and I will only figure with legend and remove others to save some space. I have wasted more than two hours but could not figure that out. Below is a sample code:
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import numpy as np
# Sample data
x, y, z = np.mgrid[0:1:10j, 0:1:10j, 0:1:10j]
values = np.sin(x**2 + y**2 + z**2)
# Create the figure
fig = make_subplots(rows=1, cols=1, specs=[[{'type': 'scene'}]], subplot_titles=['Sample Volume Plot'])
# Add the volume trace
fig.add_trace(go.Volume(
x=x.flatten(), y=y.flatten(), z=z.flatten(),
value=values.flatten(),
isomin=0, isomax=1, opacity=0.1, surface_count=15, colorscale='Inferno'
), row=1, col=1)
# Update layout to remove the legend
fig.update_layout(
title="Sample Volume Plot",
height=650, width=900,
title_x=0.5,
showlegend=False # Not working
)
# Show the plot
fig.show()
Thank you for great help. Stackoverflow is kind of my last hope.