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

Skip to content

Commit 847874a

Browse files
committed
contourf3d can now project the filled contour onto a particular plane
much like how contour3d can do with contour lines using zdir and offset arguments. svn path=/trunk/matplotlib/; revision=8915
1 parent 450eb36 commit 847874a

3 files changed

Lines changed: 48 additions & 16 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2011-01-13 Added zdir and offset arguments to contourf3d to
2+
bring contourf3d in feature parity with contour3d. - BVR
3+
14
2011-01-04 Tag 1.0.1 for release at r8896
25

36
2011-01-03 Added display of ticker offset to 3d plots. - BVR
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from mpl_toolkits.mplot3d import axes3d
2+
import matplotlib.pyplot as plt
3+
4+
fig = plt.figure()
5+
ax = fig.gca(projection='3d')
6+
X, Y, Z = axes3d.get_test_data(0.05)
7+
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
8+
cset = ax.contourf(X, Y, Z, zdir='z', offset=-100)
9+
cset = ax.contourf(X, Y, Z, zdir='x', offset=-40)
10+
cset = ax.contourf(X, Y, Z, zdir='y', offset=40)
11+
12+
ax.set_xlabel('X')
13+
ax.set_xlim3d(-40, 40)
14+
ax.set_ylabel('Y')
15+
ax.set_ylim3d(-40, 40)
16+
ax.set_zlabel('Z')
17+
ax.set_zlim3d(-100, 100)
18+
19+
plt.show()
20+

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,14 @@ def add_contour_set(self, cset, extend3d=False, stride=5, zdir='z', offset=None)
941941
z = offset
942942
art3d.line_collection_2d_to_3d(linec, z, zdir=zdir)
943943

944+
def add_contourf_set(self, cset, zdir='z', offset=None) :
945+
zdir = '-' + zdir
946+
for z, linec in zip(cset.levels, cset.collections) :
947+
if offset is not None :
948+
z = offset
949+
art3d.poly_collection_2d_to_3d(linec, z, zdir=zdir)
950+
linec.set_sort_zpos(z)
951+
944952
def contour(self, X, Y, Z, *args, **kwargs):
945953
'''
946954
Create a 3D contour plot.
@@ -1017,24 +1025,32 @@ def tricontour(self, X, Y, Z, *args, **kwargs):
10171025

10181026
def contourf(self, X, Y, Z, *args, **kwargs):
10191027
'''
1020-
Plot filled 3D contours.
1028+
Create a 3D contourf plot.
10211029
1022-
*X*, *Y*, *Z*: data points.
1030+
========== ================================================
1031+
Argument Description
1032+
========== ================================================
1033+
*X*, *Y*, Data values as numpy.arrays
1034+
*Z*
1035+
*zdir* The direction to use: x, y or z (default)
1036+
*offset* If specified plot a projection of the filled contour
1037+
on this position in plane normal to zdir
1038+
========== ================================================
10231039
10241040
The positional and keyword arguments are passed on to
10251041
:func:`~matplotlib.axes.Axes.contourf`
10261042
10271043
Returns a :class:`~matplotlib.axes.Axes.contourf`
10281044
'''
10291045

1046+
zdir = kwargs.pop('zdir', 'z')
1047+
offset = kwargs.pop('offset', None)
1048+
10301049
had_data = self.has_data()
10311050

1032-
cset = Axes.contourf(self, X, Y, Z, *args, **kwargs)
1033-
levels = cset.levels
1034-
colls = cset.collections
1035-
for z1, z2, linec in zip(levels, levels[1:], colls):
1036-
art3d.poly_collection_2d_to_3d(linec, z1)
1037-
linec.set_sort_zpos(z1)
1051+
jX, jY, jZ = art3d.rotate_axes(X, Y, Z, zdir)
1052+
cset = Axes.contourf(self, jX, jY, jZ, *args, **kwargs)
1053+
self.add_contourf_set(cset, zdir, offset)
10381054

10391055
self.auto_scale_xyz(X, Y, Z, had_data)
10401056
return cset
@@ -1063,17 +1079,10 @@ def tricontourf(self, X, Y, Z, offset=None, zdir='z', *args, **kwargs):
10631079
Returns a :class:`~matplotlib.axes.Axes.contour`
10641080
'''
10651081

1066-
zdir = '-' + zdir
10671082
had_data = self.has_data()
10681083

10691084
cset = Axes.tricontourf(self, X, Y, Z, *args, **kwargs)
1070-
levels = cset.levels
1071-
colls = cset.collections
1072-
for z1, linec in zip(levels, colls):
1073-
if offset is not None:
1074-
z1 = offset
1075-
art3d.poly_collection_2d_to_3d(linec, z1, zdir=zdir)
1076-
linec.set_sort_zpos(z1)
1085+
self.add_contourf_set(cset, zdir, offset)
10771086

10781087
self.auto_scale_xyz(X, Y, Z, had_data)
10791088
return cset

0 commit comments

Comments
 (0)