couldn't remove origin point in matplotlib polycollection

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()

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.

链接地址: http://www.djcxy.com/p/71326.html

上一篇: 我如何在Java中使用C#System.DBNull.value?

下一篇: 无法删除matplotlib polycollection中的原点