Skip to content

Commit 88106bb

Browse files
committed
Place 3D contourf patches between levels
1 parent ad4585b commit 88106bb

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

lib/matplotlib/contour.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,8 @@ def __init__(self, ax, *args,
813813
kwargs = self._process_args(*args, **kwargs)
814814
self._process_levels()
815815

816+
self._extend_min = self.extend in ['min', 'both']
817+
self._extend_max = self.extend in ['max', 'both']
816818
if self.colors is not None:
817819
ncolors = len(self.levels)
818820
if self.filled:
@@ -821,25 +823,27 @@ def __init__(self, ax, *args,
821823

822824
# Handle the case where colors are given for the extended
823825
# parts of the contour.
824-
extend_min = self.extend in ['min', 'both']
825-
extend_max = self.extend in ['max', 'both']
826+
826827
use_set_under_over = False
827828
# if we are extending the lower end, and we've been given enough
828829
# colors then skip the first color in the resulting cmap. For the
829830
# extend_max case we don't need to worry about passing more colors
830831
# than ncolors as ListedColormap will clip.
831-
total_levels = ncolors + int(extend_min) + int(extend_max)
832-
if len(self.colors) == total_levels and (extend_min or extend_max):
832+
total_levels = (ncolors +
833+
int(self._extend_min) +
834+
int(self._extend_max))
835+
if (len(self.colors) == total_levels and
836+
(self._extend_min or self._extend_max)):
833837
use_set_under_over = True
834-
if extend_min:
838+
if self._extend_min:
835839
i0 = 1
836840

837841
cmap = mcolors.ListedColormap(self.colors[i0:None], N=ncolors)
838842

839843
if use_set_under_over:
840-
if extend_min:
844+
if self._extend_min:
841845
cmap.set_under(self.colors[0])
842-
if extend_max:
846+
if self._extend_max:
843847
cmap.set_over(self.colors[-1])
844848

845849
self.collections = cbook.silent_list(None)

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,17 @@ def add_contour_set(
20692069

20702070
def add_contourf_set(self, cset, zdir='z', offset=None):
20712071
zdir = '-' + zdir
2072-
for z, linec in zip(cset.levels, cset.collections):
2072+
2073+
midpoints = cset.levels[:-1] + np.diff(cset.levels) / 2
2074+
# Linearly interpolate to get levels for any extensions
2075+
if cset._extend_min:
2076+
min_level = cset.levels[0] - np.diff(cset.levels[:2]) / 2
2077+
midpoints = np.insert(midpoints, 0, min_level)
2078+
if cset._extend_max:
2079+
max_level = cset.levels[-1] + np.diff(cset.levels[-2:]) / 2
2080+
midpoints = np.append(midpoints, max_level)
2081+
2082+
for z, linec in zip(midpoints, cset.collections):
20732083
if offset is not None:
20742084
z = offset
20752085
art3d.poly_collection_2d_to_3d(linec, z, zdir=zdir)

0 commit comments

Comments
 (0)