When I save a 3d surface plot to .pdf
with linewidth=0
I can still can see some white lines, which polutes my final output when seen in pdf format.
I strongly believe this is caused by antialiasing, so I tried antialiased=False
, as suggested by others. It works for raster images, but the pdf image still shows these lines.
Fortunately I found a similiar question for contour here, which does:
for c in cnt.collections:
c.set_edgecolor("face")
This answer looked very promising, but for 3d plots the object Poly3DCollection
has no attribute collections
.
Is there any workaround for 3d plots? I'm not proffiecient enough in Python, but I'm wondering if an analogous attribute to collections
would be the answer
code to repro this issue:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = Axes3D(fig)
x = np.linspace(-5, 5, 100)
y = np.linspace(-5, 5, 100)
x, y = np.meshgrid(x, y)
z = x**2 + y**2
s = ax.plot_surface(x, y, z, rstride = 1, cstride = 1, cmap='gray', linewidth=0, antialiased=False)
plt.savefig("3d.pdf")
Error when using collections
:
AttributeError: 'Poly3DCollection' object has no attribute 'collections'
Thanks!