I have tried an example with PolyCollection from matplotlib tutorials and noticed one strange thing. I couldn't remove this points from axes origin see fig. How do I manage this?
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()
To hide or remove X-axis labels, use set(xlabel=None). To display the figure, use show() method.
Click anywhere in the chart for which you want to display or hide axes. This displays the Chart Tools, adding the Design, Layout, and Format tabs. On the Layout tab, in the Axes group, click Axes. Click the type of axis that you want to display or hide, and then click the options that you want.
Using plt. show() in Matplotlib mode is not required.
This is a bug with the explicit closing feature of PolyCollection.
For now, turn that off, and you'll 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 here is that you shouldn't get the results you expect while running this, because the polygon shouldn't be closed. This is another, related bug with the 3D code. In any case, this only affects the line around the edge, and in your example it barely makes any difference (I originally thought it was correctly not closed until I increased the linewidth).
PolyCollection uses path.Path objects to store the vertexes, and for closed polygons, uses the CLOSEPOLY vertex code, which cleanly closes the path (no overlap in the line).
The 3D projection code for PolyCollections seems to be rather a hack which takes your PolyCollection, extracts the paths, takes the vertexes from those paths, throwing the codes for those vertexes away and assuming they're all real vertex coordinates, and then directly modifies the vertexes on your original PolyCollection to use new paths that have 2D screen projected coordinates with no codes... and regardless of your settings, are closed.
I've filed this as issue #2045.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With