On Windows, when I save 3D matplotlib surface plots using the pickle module and reload them, the plots lack any interactive functionality, such as being able to rotate the plots or zoom in on the plots. However, if I save and reload 2D pickled matplotlib plots, I am still able to interact with the plots, at least with the zoom tools. The following code recreates the successful 2D plot case.
import matplotlib.pyplot as plt
import numpy as np
import pickle
xs = np.linspace(0, 4*np.pi, 100)
ys = np.sin(xs)
fig, ax = plt.subplots()
ax.plot(xs, ys)
with open("plot.pickle", 'wb') as file:
pickle.dump(fig, file)
plt.show()
plt.close(fig)
with open("plot.pickle", 'rb') as file:
fig = pickle.load(file)
plt.show()
The following code is a small example that recreates the 3D plot problem.
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import pickle
xs = np.linspace(0, 1, 100)
ys = np.linspace(0, 4*np.pi, 100)
zs = np.zeros((100, 100))
for i, amp in enumerate(xs):
for j, phase in enumerate(ys):
zs[j, i] = amp*np.sin(phase)
xs, ys = np.meshgrid(xs, ys)
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
ax.plot_surface(xs, ys, zs)
with open("plot.pickle", 'wb') as file:
pickle.dump(fig, file)
plt.close(fig)
with open("plot.pickle", 'rb') as file:
fig = pickle.load(file)
plt.show()
What changes can I make so that my 3D pickled plots will have interactive rotate and zoom functionality? If such functionality is not possible with 3D pickled plots, are they any alternative methods for saving (without having to originally show the plot in a window) and reloading interactive 3D matplotlib surface plots?