3

I am trying to export my surface plot into a .png file. For some reason, the saving plot does not correspond to the 3D orientation of the plot showed in spyder. Here is my code:

import csv

import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
import matplotlib as mpl
import numpy as np


with open(r'path', 'r') as f:
   voltpertime = list(csv.reader(f, delimiter=","))

voltpertime = np.array(voltpertime[0:], dtype=np.float)
Z= np.flipud(voltpertime)


fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

# Make data.
X = np.arange(1, 36, 1)
Y = np.arange(-4, 8, 0.1)
X, Y = np.meshgrid(X, Y)


# Plot the surface.
norm = mpl.colors.Normalize(vmin=-0.5, vmax=7)
surf = ax.plot_surface(X, Y, Z, cmap=cm.jet, linewidth=1, antialiased=False, norm=norm)

# Customize the z axis.
ax.set_zlim(-3, 7)

ax.zaxis.set_major_locator(LinearLocator(4))

ax.zaxis.set_major_formatter('{x:.02f}')

plt.colorbar(surf, shrink=0.5, aspect=5, label='current (nA)', pad = 0.1)

plt.yticks((-4, -2, 0, 2, 4, 6, 8), ("8", "6", "4", "2", "0", "-2", "-4"))


# rotate the axes and update
for angle in range(160, 360):
   ax.view_init(35, angle)
   plt.draw()
   plt.pause(.001)


fig.savefig(r'path', 
           transparent = True, bbox_inches= 'tight', dpi=600, edgecolor= None)


plt.show()

Here is the plot in spyder: Fig1

and here is the plot when I save it: Fig2

I want to export the plot exactly how it appears in spyder.

Any idea?

Thanks

Derek O
  • 16,770
  • 4
  • 24
  • 43
WNSL
  • 31
  • 2

0 Answers0