Python 使用多集合在matplotlib mplot3d绘图中显示的奇数线伪影
我使用的是mplot3d示例,它使用PolyCollection来堆叠XY图 然而,我在情节中看到了一些奇怪的线条人工制品Python 使用多集合在matplotlib mplot3d绘图中显示的奇数线伪影,python,matplotlib,mplot3d,Python,Matplotlib,Mplot3d,我使用的是mplot3d示例,它使用PolyCollection来堆叠XY图 然而,我在情节中看到了一些奇怪的线条人工制品 如何删除从可见区域消失的水平线 是否有更好的方法沿深度方向堆叠XY图 下面的脚本生成此情节 from mpl_toolkits.mplot3d import Axes3D from matplotlib.collections import PolyCollection from matplotlib.colors import colorConverter impor
- 如何删除从可见区域消失的水平线
- 是否有更好的方法沿深度方向堆叠XY图
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
zs = []
fig = plt.figure()
ax = fig.gca(projection='3d')
verts = []
# XY data (i.e. "normal line plots")
count = 4
for i in range(count):
xs, ys = [800.0, 900.0, 1000.0, 1100.], [0., 1., 1., 0.]
verts.append(list(zip(xs, ys)))
# Z position (i.e. depth at which the XY plot is drawn)
zs = [0,1,2,3]
colours = plt.cm.Blues(np.linspace(0.2, 0.8, len(zs)))
poly = PolyCollection(verts, facecolors = colours )
ax.add_collection3d(poly, zs=zs, zdir='y')
ax.set_xlabel('X')
ax.set_xlim3d(800,1150)
ax.set_ylabel('Y')
ax.set_ylim3d(0, 4)
ax.set_zlabel('Z')
ax.set_zlim3d(0, 1)
plt.show()
如果仍然存在此问题,请尝试手动更改相应的路径对象。应修改最后一个要停止的顶点的代码(代码0): 。。。结果如下:
对我来说,这看起来像个虫子。您可能应该在matplotlib bug跟踪器中添加一个记录单。我发布的脚本是示例脚本的一个稍加修改的版本,基本上只是更改了数据。为什么你认为这个例子有效,而这个不行?肯定是个bug?当你改变x坐标时,这个例子也显示了这个bug。matplotlib似乎在多边形的(0,0)处插入了一个附加点。对我来说,这看起来像个虫子。我还没有意识到这一点,谢谢你指出这一点。我在github上添加了一个问题。你不知道z-堆叠xy图的另一种方法,是吗?也许我需要使用gnuplot?这很有效,但您也可以像上面的@tcaswell注释那样执行
PolyCollection(…closed=False)
。
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
zs = []
fig = plt.figure()
ax = fig.gca(projection='3d')
verts = []
# XY data (i.e. "normal line plots")
count = 4
for i in range(count):
xs, ys = [800.0, 900.0, 1000.0, 1100.], [0., 1., 1., 0.]
verts.append(list(zip(xs, ys)))
# Z position (i.e. depth at which the XY plot is drawn)
zs = [0,1,2,3]
colours = plt.cm.Blues(np.linspace(0.2, 0.8, len(zs)))
poly = PolyCollection(verts, facecolors = colours )
for path in poly.get_paths() : # There is the fix :
path.codes[-1] = 0 # we have to manually switch the last point in a path to STOP (code = 0)
ax.add_collection3d(poly, zs=zs, zdir='y')
ax.set_xlabel('X')
ax.set_xlim3d(800,1150)
ax.set_ylabel('Y')
ax.set_ylim3d(0, 4)
ax.set_zlabel('Z')
ax.set_zlim3d(0, 1)
plt.show()