Failed to delete origin in polyplollection matplotlib

I tried the PolyCollection example from matplotlib tutorials and noticed one strange thing. I could not remove these points from the origin of the axes, see Fig. How can I do it?

enter image description here

from mpl_toolkits.mplot3d import Axes3D from matplotlib.collections import PolyCollection from matplotlib.colors import colorConverter import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.gca(projection='3d') cc = lambda arg: colorConverter.to_rgba(arg, alpha=0.6) xs = np.arange(5, 10, 0.4) verts = [] zs = [0.0, 1.0, 2.0, 3.0] for z in zs: ys = np.random.rand(len(xs)) ys[0], ys[-1] = 0.1, 0 verts.append(list(zip(xs, ys))) poly = PolyCollection(verts, facecolors = [cc('r'), cc('g'), cc('b'), cc('y')]) poly.set_alpha(0.7) ax.add_collection3d(poly, zs=zs, zdir='y') ax.set_xlabel('X') ax.set_xlim3d(0, 10) ax.set_ylabel('Y') ax.set_ylim3d(-1, 4) ax.set_zlabel('Z') ax.set_zlim3d(0, 1) plt.show() 
+7
source share
1 answer

This is a bug with the explicit PolyCollection close function.

For now, turn this off, and you will get what I think is the result you expect:

 poly = PolyCollection(verts, facecolors = [cc('r'), cc('g'), cc('b'), cc('y')], closed=False) 

The only problem is that you should not get the expected results while doing this, because the polygon should not close. This is another related error with the 3D code. In any case, this only affects the line around the edge, and in your example it hardly matters (at first I thought it was correctly closed until I increased the line width).

PolyCollection uses path.Path objects to store vertices, and for closed polygons, the CLOSEPOLY vertex code is used, which purely closes the path (does not overlap in the line).

The 3D projection code for PolyCollections seems more like a hack that takes your PolyCollection, extracts the paths, takes vertices from these paths, throwing codes for those vertices and assuming that they are all real vertex coordinates, and then directly modify the vertices on the original PolyCollection to use new paths that have a 2D screen, projected coordinates without codes ... and regardless of your settings, are closed.

I registered this as question # 2045 .

+4
source

All Articles