When trying to enforce rasterization of a Poly3DCollection
object in Matplotlib, I get the following error message (and I can confirm no rasterization is applied):
/usr/lib/python3/dist-packages/matplotlib/artist.py:788: UserWarning: Rasterization of '<mpl_toolkits.mplot3d.art3d.Poly3DCollection object at 0x2b49e8faeba8>' will be ignored
warnings.warn("Rasterization of '%s' will be ignored" % self)
It is possible to rasterize the entire figure, but it is obviously preferable to only rasterize some objects, while keeping items like axes, labels, key, text, etc. as vector graphics.
I have tried using the following syntax in my code:
ax.add_collection3d(Poly3DCollection(polygons, rasterized=True), zs='z')
c = Poly3DCollection(polygons)
and thenc.set_rasterized(True)
According to this post, it is possible to rasterize a PolyCollection
(without the 3D bit) object.
Any suggestions?
Here is an MWE:
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim([0, 4])
ax.set_ylim([0, 4])
ax.set_zlim([0, 4])
polygons = [[(3, 1, 1), (1, 3, 1), (1, 1, 3)]]
ax.add_collection3d(Poly3DCollection(polygons, facecolors='r', rasterized=True), zs='z')
plt.show()