I am looking for a way to simultaneously visualize two simple interfaces that I have for 3d (point cloud) and 2d (photo) data visualization. One is with tkinter and matplotlib, and another with open3d. Separately or sequentially they work without any issues. However, I want user to be able to have them side-by-side since they represent same dataset, and visual comparison might be of use.
I somewhat naively tried to do it with threads (I have no significant experience with threads), but it seems that this is not supported(?).
After throwing away all code irrelevant to the question (including tkinter, as problem is in matplotlib itself):
import threading
import numpy as np
import matplotlib.pyplot as plt
import open3d as o3d
# Function to plot random 2D data using matplotlib
def plot_random_2d():
plt.ion() # Turn on interactive mode
fig, ax = plt.subplots()
x = np.random.rand(100)
y = np.random.rand(100)
ax.scatter(x, y)
ax.set_title("Random 2D Data")
plt.show()
# Function to plot random 3D data using open3d
def plot_random_3d():
pcd = o3d.geometry.PointCloud()
points = np.random.rand(100, 3)
pcd.points = o3d.utility.Vector3dVector(points)
vis = o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(pcd)
vis.run()
vis.destroy_window()
# Main function to run both plots concurrently
def main():
thread_2d = threading.Thread(target=plot_random_2d)
thread_3d = threading.Thread(target=plot_random_3d)
thread_2d.start()
thread_3d.start()
thread_2d.join()
thread_3d.join()
if __name__ == "__main__":
main()
Dependencies: pip install matplotlib numpy open3d
Note: both plots are interactive in the final use-case, so any proposed solution should support interactivity.
Is there any way to solve this issue with the current approach? Or should I trash it completely and look for different library entirely? (I thought about Plotly, but not sure how much is supports 2d/3d points selection, and also it seems to be slow for point cloud visualization).