I’m running a local instance from streamlit and trying to view a 3D plot from a live stream data. Using st.empy i was able to update chart without update entire screen but if i rotate screen, it reset view on every refresh, tried a lot of solutions, but without sucess, there is some post withour a solution. Is a version problem?
Update 3d scatter plot without resetting view - Using Streamlit - Streamlit
import streamlit as st
import numpy as np
import plotly.graph_objs as go
import time
plot = st.empty()
while True:
with plot:
values = np.random.uniform(20, 80, 8) # Valores aleatórios entre 20 e 80 °C
zonas = [f'Zona {i+1}' for i in range(8)]
corners = np.array([[0, 0, 0], [2, 0, 0], [2, 1, 0], [0, 1, 0],
[0, 0, 1], [2, 0, 1], [2, 1, 1], [0, 1, 1]])
grid_x, grid_y, grid_z = np.mgrid[0:2:20j, 0:1:20j, 0:1:20j]
grid_values = np.interp(np.linspace(0, 7, grid_x.size), np.arange(8), values).reshape(grid_x.shape)
fig = go.Figure(data=go.Volume(
x=grid_x.flatten(),
y=grid_y.flatten(),
z=grid_z.flatten(),
value=grid_values.flatten(),
isomin=min(values),
isomax=max(values),
opacity=0.3,
surface_count=50,
colorscale='Viridis',
))
annos = [dict(x=corners[i, 0], y=corners[i, 1], z=corners[i, 2],
text=f'{values[i]:.1f}',
showarrow=True, arrowhead=0, font=dict(color='black', size=14),
bgcolor="white", opacity=0.85) for i in range(8)]
fig.update_layout(
scene=dict(
annotations=annos,
xaxis=dict(range=[-0.5, 2.5]),
yaxis=dict(range=[-0.5, 1.5]),
zaxis=dict(range=[-0.5, 1.5])
),
width=1000,
height=800,
uirevision='foo' # Mantém o estado da UI entre atualizações
)
st.plotly_chart(fig, use_container_width=True)
time.sleep(3)