When trying to force rasterization of an object Poly3DCollection
in Matplotlib, the following error message appears (and I can confirm that rasterization is not 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)
You can rasterize the entire figure, but it is obviously preferable to rasterize some objects, preserving elements such as axes, labels, key, text, etc. as vector graphics.
I tried using the following syntax in my code:
ax.add_collection3d(Poly3DCollection(polygons, rasterized=True), zs='z')
c = Poly3DCollection(polygons)
, and then c.set_rasterized(True)
According to this message, you can rasterize an object PolyCollection
(without 3D bits).
Any suggestions?
Here is the 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()
source
share