Saving Matplotlib suface-plot with transparent background

392 views Asked by At

I try to save my 3d-Plot with an transparent background but with the transparent=True-Parameter of savefig it doesnt work. is there an other way to do it?

Here is my actual attemp:

import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
from scipy import interpolate


Z = abs(p_r) #p_r = 2-dimensional complex valued numpy-Array (4x4) 

X, Y = np.meshgrid(np.arange(-0.06, 0.07, 0.04), np.arange(-0.06, 0.07, 0.04))
xnew, ynew = np.mgrid[-0.06:0.06:10j, -0.06:0.06:10j]
tck = interpolate.bisplrep(X, Y, Z, s=0)
znew = interpolate.bisplev(xnew[:,0], ynew[0,:], tck)

fig = plt.figure()
ax = fig.gca(projection='3d')
    
surf = ax.plot_surface(xnew, ynew, znew,
                    cmap=cmap,linewidth=0, antialiased=False, shade=False)

ax.set_zlim(0, 0.9)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))

ax.set_xlabel('x [m]')
ax.set_ylabel('y [m]')
ax.set_zlabel('Amplitude [Pa]')

plt.savefig(graphpath, tranparent=True)
0

There are 0 answers