Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a44572

Browse files
committed
mplot3d: fix axes juggle issue, fix ticks on end of axes range
svn path=/trunk/matplotlib/; revision=8041
1 parent d77a57f commit 9a44572

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

examples/mplot3d/polys3d_demo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
poly.set_alpha(0.7)
2323
ax.add_collection3d(poly, zs=zs, zdir='y')
2424

25+
ax.set_xlabel('X')
2526
ax.set_xlim3d(0, 10)
27+
ax.set_ylabel('Y')
2628
ax.set_ylim3d(-1, 4)
29+
ax.set_zlabel('Z')
2730
ax.set_zlim3d(0, 1)
2831

2932
plt.show()

examples/mplot3d/surface3d_demo3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,
2424
linewidth=0, antialiased=False)
2525

26-
ax.set_zlim3d(-1.01, 1.01)
27-
ax.w_zaxis.set_major_locator(LinearLocator(10))
26+
ax.set_zlim3d(-1, 1)
27+
ax.w_zaxis.set_major_locator(LinearLocator(6))
2828
ax.w_zaxis.set_major_formatter(FormatStrFormatter('%.03f'))
2929

3030
plt.show()

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,24 @@ def poly_collection_2d_to_3d(col, zs=0, zdir='z'):
434434

435435
def juggle_axes(xs, ys, zs, zdir):
436436
"""
437-
Reorder coordinates so that zdir
437+
Reorder coordinates so that 2D xs, ys can be plotted in the plane
438+
orthogonal to zdir. zdir is normally x, y or z. However, if zdir
439+
starts with a '-' it is interpreted as a compensation for rotate_axes.
440+
"""
441+
if zdir == 'x':
442+
return zs, xs, ys
443+
elif zdir == 'y':
444+
return xs, zs, ys
445+
elif zdir[0] == '-':
446+
return rotate_axes(xs, ys, zs, zdir)
447+
else:
448+
return xs, ys, zs
449+
450+
def rotate_axes(xs, ys, zs, zdir):
451+
"""
452+
Reorder coordinates so that the axes are rotated with zdir along
453+
the original z axis. Prepending the axis with a '-' does the
454+
inverse transform, so zdir can be x, -x, y, -y, z or -z
438455
"""
439456
if zdir == 'x':
440457
return ys, zs, xs

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ def contour(self, X, Y, Z, levels=10, **kwargs):
857857

858858
had_data = self.has_data()
859859

860-
jX, jY, jZ = art3d.juggle_axes(X, Y, Z, zdir)
860+
jX, jY, jZ = art3d.rotate_axes(X, Y, Z, zdir)
861861
cset = Axes.contour(self, jX, jY, jZ, **kwargs)
862862

863863
zdir = '-' + zdir

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def draw(self, renderer):
180180
# filter locations here so that no extra grid lines are drawn
181181
interval = self.get_view_interval()
182182
majorLocs = [loc for loc in majorLocs if \
183-
interval[0] < loc < interval[1]]
183+
interval[0] <= loc <= interval[1]]
184184
self.major.formatter.set_locs(majorLocs)
185185
majorLabels = [self.major.formatter(val, i)
186186
for i, val in enumerate(majorLocs)]

0 commit comments

Comments
 (0)