I am trying to visualize multiple 2d trajectories (x, y) in a 3D scatter plot where the z axis is time.
import numpy as np
import pandas as pd
import plotly.express as px
# Sample data: 3 trajectories
t = np.linspace(0, 10, 200)
df = pd.concat([pd.DataFrame({'x': 900 * (1 + np.cos(t + 5 * i)), 'y': 400 * (1 + np.sin(t)), 't': t, 'id': f'id000{i}'}) for i in [0, 1, 2]])
# 3d scatter plot
fig = px.scatter_3d(df, x='x', y='y', z='t', color='id', )
fig.update_traces(marker=dict(size=2))
fig.show()
I have a .png file of a map with size: 2000x1000. The (x, y) coordinates of the trajectories correspond to the pixel locations of the map.
I would like to see the image of the map on the "floor" of the 3d scatter plot.
I have tried to add the image with this code:
from scipy import misc
img = misc.imread('images/map_bg.png')
fig2 = px.imshow(img)
fig.add_trace(fig2.data[0])
fig.show()
But the result is having an independent image in the background as a separate plot:
And I want the image on the "floor" of the scatter plot and moving with the scatter plot, if I rotate/zoom. Here is a mock:
Additional note: There can be any number of trajectories and for my application, it is important that each trajectory is automatically plotted with a different color. I am using plotly.express
, but I can use other plotly packages, as long as these requirements are met.