I want to create a 3D animation, fixed perspective, and axis. But I tried many ways to fail.
My code :
from plotly.offline import plot
import plotly.graph_objs as go
import numpy as np
from tensorflow.python.keras.datasets import fashion_mnist
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
y_test = y_test[:1000]
datas = np.load('tmp/latent/his.npz', allow_pickle=True)
his = datas['arr_0'][()] # type: dict
# ๅฎไนๅๅงๆฐๆฎ
data = [go.Scatter3d(x=his['000'][:, 0], y=his['000'][:, 1], z=his['000'][:, 2],
mode='markers', type='scatter3d', marker={'size': 5, 'color': y_test, 'colorscale': 'Viridis'})]
# ๅๅงๅธๅฑ
layout = go.Layout(
xaxis={'range': [-5, 5], 'fixedrange': True, 'rangemode': 'tozero', 'tickmode': "linear", 'tick0': -5, 'dtick': 1, 'automargin': False},
yaxis={'range': [-5, 5], 'fixedrange': True, 'rangemode': 'tozero', 'tickmode': "linear", 'tick0': -5, 'dtick': 1, 'automargin': False},
updatemenus=[{
'buttons': [{'args': [None], 'label':'Play', 'method':'animate'}],
'xanchor':'center',
'yanchor':'bottom',
'pad':{'l': 30},
'showactive': False,
'type': 'buttons'}],
scene={
'xaxis': {'range': [-5, 5], 'rangemode': 'tozero', 'tickmode': "linear", 'tick0': -5, 'dtick': 1},
'yaxis': {'range': [-5, 5], 'rangemode': 'tozero', 'tickmode': "linear", 'tick0': -5, 'dtick': 1},
'zaxis': {'range': [-5, 5], 'rangemode': 'tozero', 'tickmode': "linear", 'tick0': -5, 'dtick': 1},
'aspectratio': {
'x': 0,
'y': 0,
'z': 0,
}},
margin={'autoexpand': False},
autosize=False,
width=1000,
height=1000)
frames = [{
'data': [go.Scatter3d(
x=v[:, 0], y=v[:, 1], z=v[:, 2],
mode='markers', marker={'size': 5, 'color': y_test, 'colorscale': 'Viridis'}
)]} for i, (k, v) in enumerate(his.items())]
fig = go.Figure(data=data, layout=layout, frames=frames)
plot(fig)
Anyone can help me? Thanks