2

我尝试使用透明背景保存我的 3d-Plot,但使用 savefig 的 transparent=True-Parameter 它不起作用。还有其他方法吗?

这是我的实际尝试:

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)
4

0 回答 0