2

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)
Samuel K.
  • 180
  • 1
  • 1
  • 11
  • sorry i changed that – Samuel K. Oct 24 '20 at 13:37
  • 1
    Still not fully reproducible but I tested it, and it seems to be a problem specific to the 3D projection, at least when storing as `png` files. Gives out the warning `MatplotlibDeprecationWarning: savefig() got unexpected keyword argument "tranparent" which is no longer supported as of 3.3 and will become an error two minor releases later plt.savefig("test_transp.png", tranparent=True)`. This error message does not appear in 2D projections, and the png file has a transparent background. – Mr. T Oct 24 '20 at 14:02

0 Answers0