Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in mplot3D with PolyCollection: (0, 0) data point is always inserted into the data set. #2533

Closed
danieljfarrell opened this issue Oct 21, 2013 · 3 comments

Comments

@danieljfarrell
Copy link

This a a bug related to stacked xy-plots example,
http://matplotlib.org/examples/mplot3d/polys3d_demo.html

matplotlib seems to be inserting a vertex at (0,0) into the data set.

  • Is there a different way to plot stacked xy-plots that avoids this bug?
  • Maybe the fix is fairly simple, if all that is happening is that an additional vertex is getting inserted?

The following example is based on the poly3d_demo script linked above. If we change the data set so that the data doesn't include a point at x=0, for example change line 12 from,

xs = np.arange(0, 10, 0.4)

to,

xs = np.arange(5, 10, 0.4)

A erroneous line is drawn from the data set to the (0,0) point.

The following script produces the result(s) below, using matplotlib 1.3.0.

Example 1
figure_1

When the x-axis is changed to only include the range of the data set the result look even worse,

Example 2
figure_2

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) # The data x-range has been changed to run between 5--10
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, 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(5, 10) # This has been changed to 5 to adjust the axis range to the data
ax.set_ylabel('Y')
ax.set_ylim3d(-1, 4)
ax.set_zlabel('Z')
ax.set_zlim3d(0, 1)

plt.show()
@mdboom
Copy link
Member

mdboom commented Oct 21, 2013

@WeatherGod: any thoughts?

@tacaswell
Copy link
Member

@tacaswell
Copy link
Member

closed by #3239

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants