diff --git a/doc/api/next_api_changes/2018-06-09-EF-contour_levels.rst b/doc/api/next_api_changes/2018-06-09-EF-contour_levels.rst new file mode 100644 index 000000000000..9e18dbbe8cb6 --- /dev/null +++ b/doc/api/next_api_changes/2018-06-09-EF-contour_levels.rst @@ -0,0 +1,16 @@ +Contour color autoscaling improvements +-------------------------------------- + +Selection of contour levels is now the same for contour and +contourf; previously, for contour, levels outside the data range were +deleted. (Exception: if no contour levels are found within the +data range, the `levels` attribute is replaced with a list holding +only the minimum of the data range.) + +When contour is called with levels specified as a target number rather +than a list, and the 'extend' kwarg is used, the levels are now chosen +such that some data typically will fall in the extended range. + +When contour is called with a `LogNorm` or a `LogLocator`, it will now +select colors using the geometric mean rather than the arithmetic mean +of the contour levels. diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index 81eedc06fe2d..3eede0126d4e 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -1174,6 +1174,9 @@ def _autolev(self, N): """ Select contour levels to span the data. + The target number of levels, *N*, is used only when the + scale is not log and default locator is used. + We need two more levels for filled contours than for line contours, because for the latter we need to specify the lower and upper boundary of each range. For example, @@ -1181,6 +1184,7 @@ def _autolev(self, N): one contour line, but two filled regions, and therefore three levels to provide boundaries for both regions. """ + self._auto = True if self.locator is None: if self.logscale: self.locator = ticker.LogLocator() @@ -1188,8 +1192,27 @@ def _autolev(self, N): self.locator = ticker.MaxNLocator(N + 1, min_n_ticks=1) lev = self.locator.tick_values(self.zmin, self.zmax) - self._auto = True - return lev + + try: + if self.locator._symmetric: + return lev + except AttributeError: + pass + + # Trim excess levels the locator may have supplied. + under = np.nonzero(lev < self.zmin)[0] + i0 = under[-1] if len(under) else 0 + over = np.nonzero(lev > self.zmax)[0] + i1 = over[0] + 1 if len(over) else len(lev) + if self.extend in ('min', 'both'): + i0 += 1 + if self.extend in ('max', 'both'): + i1 -= 1 + + if i1 - i0 < 3: + i0, i1 = 0, len(lev) + + return lev[i0:i1] def _contour_level_args(self, z, args): """ @@ -1220,8 +1243,8 @@ def _contour_level_args(self, z, args): if not self.filled: inside = (self.levels > self.zmin) & (self.levels < self.zmax) - self.levels = self.levels[inside] - if len(self.levels) == 0: + levels_in = self.levels[inside] + if len(levels_in) == 0: self.levels = [self.zmin] warnings.warn("No contour levels were found" " within the data range.") @@ -1246,27 +1269,28 @@ def _process_levels(self): # (Colorbar needs this even for line contours.) self._levels = list(self.levels) + if self.logscale: + lower, upper = 1e-250, 1e250 + else: + lower, upper = -1e250, 1e250 + if self.extend in ('both', 'min'): - self._levels.insert(0, min(self.levels[0], self.zmin) - 1) + self._levels.insert(0, lower) if self.extend in ('both', 'max'): - self._levels.append(max(self.levels[-1], self.zmax) + 1) + self._levels.append(upper) self._levels = np.asarray(self._levels) if not self.filled: self.layers = self.levels return - # layer values are mid-way between levels - self.layers = 0.5 * (self._levels[:-1] + self._levels[1:]) - # ...except that extended layers must be outside the - # normed range: - if self.extend in ('both', 'min'): - if self.logscale: - self.layers[0] = 1e-150 - else: - self.layers[0] = -1e150 - if self.extend in ('both', 'max'): - self.layers[-1] = 1e150 + # Layer values are mid-way between levels in screen space. + if self.logscale: + # Avoid overflow by taking sqrt before multiplying. + self.layers = (np.sqrt(self._levels[:-1]) + * np.sqrt(self._levels[1:])) + else: + self.layers = 0.5 * (self._levels[:-1] + self._levels[1:]) def _process_colors(self): """ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.pdf b/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.pdf index 39a7fac1c5b7..f4090c83aad3 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.pdf and b/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.png b/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.png index 4097aad6bc12..abca7ea4a6bb 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.png and b/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.svg b/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.svg index def44e917861..b60e679f6b3a 100644 --- a/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.svg +++ b/lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.svg @@ -1,8 +1,8 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +L 0 3.5 +" id="mba93285ecf" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -17711,7 +14417,7 @@ L 73.1875 35.5 L 73.1875 27.203125 L 10.59375 27.203125 z -" id="DejaVuSans-2212"/> +" id="DejaVuSans-8722"/> +" id="DejaVuSans-51"/> - - - + + + - - - - - - + - + @@ -17788,23 +14489,18 @@ Q 49.859375 40.875 45.40625 35.40625 Q 44.1875 33.984375 37.640625 27.21875 Q 31.109375 20.453125 19.1875 8.296875 z -" id="DejaVuSans-32"/> +" id="DejaVuSans-50"/> - - - + + + - - - - - - + - + @@ -17822,23 +14518,18 @@ L 54.390625 8.296875 L 54.390625 0 L 12.40625 0 z -" id="DejaVuSans-31"/> +" id="DejaVuSans-49"/> - - - + + + - - - - - - + - + @@ -17864,76 +14555,56 @@ Q 6.59375 17.96875 6.59375 36.375 Q 6.59375 54.828125 13.0625 64.515625 Q 19.53125 74.21875 31.78125 74.21875 z -" id="DejaVuSans-30"/> +" id="DejaVuSans-48"/> - - + + - - - - - - + - + - - + + - - - - - - + - + - - + + - - - - - - + - + - - + + - - - - - - + - + @@ -17955,22 +14626,17 @@ L 37.796875 17.1875 L 4.890625 17.1875 L 4.890625 26.703125 z -" id="DejaVuSans-34"/> +" id="DejaVuSans-52"/> - - + + - - - - - - + - + @@ -17999,391 +14665,3371 @@ Q 35.15625 39.890625 26.703125 39.890625 Q 22.75 39.890625 18.8125 39.015625 Q 14.890625 38.140625 10.796875 36.28125 z -" id="DejaVuSans-35"/> +" id="DejaVuSans-53"/> - - + + - - - - - - - - - + +L -3.5 0 +" id="mc8a02073fc" style="stroke:#000000;stroke-width:0.8;"/> - + - - - + + + - - - - - - + - + - - - + + + - - - - - - + - + - - - + + + - - - - - - + - + - - + + - - - - - - + - + - - + + - - - - - - + - + - - + + - - - - - - + - + - - + + - - - - - - + - + - - + + - - - - - - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + @@ -18394,7 +18040,7 @@ L 21 12.40625 L 21 0 L 10.6875 0 z -" id="DejaVuSans-2e"/> +" id="DejaVuSans-46"/> +" id="DejaVuSans-54"/> - - - - - + + + + + - + - + - - - - - + + + + + - + - + @@ -18497,116 +18143,183 @@ Q 38.140625 66.40625 31.78125 66.40625 Q 25.390625 66.40625 21.84375 63.234375 Q 18.3125 60.0625 18.3125 54.390625 z -" id="DejaVuSans-38"/> +" id="DejaVuSans-56"/> - - - - - + + + + + - + - + - - - - - + + + + + - + - + - - - - + + + + - + - + - - - - + + + + - + - + - - - - + + + + - + - + - - - - + + + + - + - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + diff --git a/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.pdf b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.pdf index f79e7605a34a..ac6f579cdafc 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.pdf and b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.png b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.png index 2090e4d208a3..0aa9049a87ae 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.png and b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.svg b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.svg index d4dba2221dc8..2cfa55ec7696 100644 --- a/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.svg +++ b/lib/matplotlib/tests/baseline_images/test_axes/contour_hatching.svg @@ -1,8 +1,8 @@ - - + + - - - - - + - + - + - + +" style="fill:url(#he7211442b0);fill-opacity:0.5;"/> - - + - + - + - + +" style="fill:url(#hc8e4ad36cd);fill-opacity:0.5;"/> - - + - + - + - + +" style="fill:url(#h8124db33bb);fill-opacity:0.5;"/> - - + - + - + - + - + +" style="fill:url(#hb1742779c6);fill-opacity:0.5;"/> - - + - + +" style="fill:url(#hcbba77881f);fill-opacity:0.5;"/> - - + - + - + +" style="fill:url(#h11d5e7b694);fill-opacity:0.5;"/> - - + - + +" style="fill:url(#h3be0aff0a3);fill-opacity:0.5;"/> - - + - - - - - - - - - - - - - +" style="fill:url(#h779f96334f);fill-opacity:0.5;"/> +L 0 3.5 +" id="ma57288aa69" style="stroke:#000000;stroke-width:0.8;"/> - - - - - - - - - - - - - - - - - - - - + - - - - - - + - - - - - - - - - - - + - - - - - - + - - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - + - - - - - - - + - - - - - - + - - - - - - - + - - - - - - + - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - - - - + +L -3.5 0 +" id="m9a4ee1f972" style="stroke:#000000;stroke-width:0.8;"/> - - - - - - - - + - - - - - - + - - - - - - - - + - - - - - - + - - - - - - - - + - - - - - - + - - - - - - - + - - - - - - + - - - - - - - + - - - - - - + - - - - - - - + - - - - - - + - - - - - - - + - - - - - - + - - - - - - - + - - - - - - + - - - - - - - + + + + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - + - + - + - + - + - + @@ -109,68 +109,72 @@ L 0 3.5 +" id="m57021d4b2f" style="stroke:#000000;stroke-width:0.8;"/> - + - + - + - + - + - + + + +" style="fill:none;stroke:#443983;stroke-width:1.5;"/> - - + - + +" style="fill:none;stroke:#31688e;stroke-width:1.5;"/> - - + - - - + - + +" style="fill:none;stroke:#35b779;stroke-width:1.5;"/> - - + +" style="fill:none;stroke:#90d743;stroke-width:1.5;"/> + - + +" id="DejaVuSans-51"/> +" id="DejaVuSans-46"/> +" id="DejaVuSans-48"/> - - - - - - + + + + + + - + +" id="DejaVuSans-52"/> +" id="DejaVuSans-53"/> - - - - - + + + + + - + +" id="DejaVuSans-54"/> - - - - - - + + + + + + - + diff --git a/lib/matplotlib/tests/baseline_images/test_contour/contour_test_label_transforms.png b/lib/matplotlib/tests/baseline_images/test_contour/contour_test_label_transforms.png index 59176950533e..723e501ed287 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_contour/contour_test_label_transforms.png and b/lib/matplotlib/tests/baseline_images/test_contour/contour_test_label_transforms.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.pdf b/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.pdf index 9a5b3f3d3ca5..18b2e46e0f11 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.pdf and b/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.png b/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.png index 4ba990cdcdc2..aa1d865353ec 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.png and b/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.svg b/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.svg index 3790836f4405..c12572fa9384 100644 --- a/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.svg +++ b/lib/matplotlib/tests/baseline_images/test_lines/line_collection_dashes.svg @@ -1,8 +1,8 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +L 0 3.5 +" id="m3c049a1f51" style="stroke:#000000;stroke-width:0.8;"/> - - - - - - - - - + - - - - - - + - + - - - - - - + - + - - - - - - + - + - - - - - - + - + - - - - - - + - + - + +L -3.5 0 +" id="mee99decfa6" style="stroke:#000000;stroke-width:0.8;"/> - + - - - - + + + - + - - + + - + - + + + - + - - + + - + - + + + - + - - + + - + - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/lib/matplotlib/tests/baseline_images/test_patheffects/collection.pdf b/lib/matplotlib/tests/baseline_images/test_patheffects/collection.pdf index 1adf8eef8a5b..d74333643910 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_patheffects/collection.pdf and b/lib/matplotlib/tests/baseline_images/test_patheffects/collection.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_patheffects/collection.png b/lib/matplotlib/tests/baseline_images/test_patheffects/collection.png index 90e62bdbea4b..07410efba929 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_patheffects/collection.png and b/lib/matplotlib/tests/baseline_images/test_patheffects/collection.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_patheffects/collection.svg b/lib/matplotlib/tests/baseline_images/test_patheffects/collection.svg index d65624e4d375..988cc34ebe56 100644 --- a/lib/matplotlib/tests/baseline_images/test_patheffects/collection.svg +++ b/lib/matplotlib/tests/baseline_images/test_patheffects/collection.svg @@ -1,8 +1,8 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +" id="DejaVuSans-49"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - + + + + + - - - - - - - - - - - - - + + - - - - + + - - - - - - + + - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - - - - - + + - - - + + + + + + + - - - - - diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 093c89d7c0b9..35f620e7775b 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1593,18 +1593,20 @@ def contour_dat(): return x, y, z -@image_comparison(baseline_images=['contour_hatching']) +@image_comparison(baseline_images=['contour_hatching'], + remove_text=True, style='mpl20') def test_contour_hatching(): x, y, z = contour_dat() fig = plt.figure() ax = fig.add_subplot(111) - cs = ax.contourf(x, y, z, hatches=['-', '/', '\\', '//'], + cs = ax.contourf(x, y, z, 7, hatches=['/', '\\', '//', '-'], cmap=plt.get_cmap('gray'), extend='both', alpha=0.5) -@image_comparison(baseline_images=['contour_colorbar']) +@image_comparison(baseline_images=['contour_colorbar'], + style='mpl20') def test_contour_colorbar(): x, y, z = contour_dat() diff --git a/lib/matplotlib/tests/test_contour.py b/lib/matplotlib/tests/test_contour.py index 76af52341de9..0acaf6580006 100644 --- a/lib/matplotlib/tests/test_contour.py +++ b/lib/matplotlib/tests/test_contour.py @@ -242,7 +242,7 @@ def test_contour_datetime_axis(): @image_comparison(baseline_images=['contour_test_label_transforms'], - extensions=['png'], remove_text=True) + extensions=['png'], remove_text=True, style='mpl20') def test_labels(): # Adapted from pylab_examples example code: contour_demo.py # see issues #2475, #2843, and #2818 for explanation @@ -371,7 +371,7 @@ def test_contourf_log_extension(): ax3 = fig.add_subplot(133) # make data set with large range e.g. between 1e-8 and 1e10 - data_exp = np.linspace(-8, 10, 1200) + data_exp = np.linspace(-7.5, 9.5, 1200) data = np.power(10, data_exp).reshape(30, 40) # make manual levels e.g. between 1e-4 and 1e-6 levels_exp = np.arange(-4., 7.) diff --git a/lib/matplotlib/tests/test_lines.py b/lib/matplotlib/tests/test_lines.py index 4b83ac05899a..85e0405c18b8 100644 --- a/lib/matplotlib/tests/test_lines.py +++ b/lib/matplotlib/tests/test_lines.py @@ -144,7 +144,8 @@ def test_set_drawstyle(): assert len(line.get_path().vertices) == len(x) -@image_comparison(baseline_images=['line_collection_dashes'], remove_text=True) +@image_comparison(baseline_images=['line_collection_dashes'], + remove_text=True, style='mpl20') def test_set_line_coll_dash_image(): fig = plt.figure() ax = fig.add_subplot(1, 1, 1) diff --git a/lib/matplotlib/tests/test_patheffects.py b/lib/matplotlib/tests/test_patheffects.py index 98b64d149b42..6e80d8d98b17 100644 --- a/lib/matplotlib/tests/test_patheffects.py +++ b/lib/matplotlib/tests/test_patheffects.py @@ -119,7 +119,7 @@ def test_SimplePatchShadow_offset(): assert pe._offset == (4, 5) -@image_comparison(baseline_images=['collection'], tol=0.02) +@image_comparison(baseline_images=['collection'], tol=0.02, style='mpl20') def test_collection(): x, y = np.meshgrid(np.linspace(0, 10, 150), np.linspace(-5, 5, 100)) data = np.sin(x) + np.cos(y) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 334dc42dc650..a6d1f7280841 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -1996,8 +1996,11 @@ def _3d_extend_contour(self, cset, stride=5): dz = (levels[1] - levels[0]) / 2 for z, linec in zip(levels, colls): - topverts = art3d.paths_to_3d_segments(linec.get_paths(), z - dz) - botverts = art3d.paths_to_3d_segments(linec.get_paths(), z + dz) + paths = linec.get_paths() + if not paths: + continue + topverts = art3d.paths_to_3d_segments(paths, z - dz) + botverts = art3d.paths_to_3d_segments(paths, z + dz) color = linec.get_color()[0] diff --git a/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.pdf b/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.pdf index d72cfee76b9b..5a7250708c9a 100644 Binary files a/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.pdf and b/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.pdf differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.png b/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.png index a8aa9cab3161..ba603596e4b3 100644 Binary files a/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.png and b/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.svg b/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.svg index 85c9eca23f97..943adc627c98 100644 --- a/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.svg +++ b/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/contour3d.svg @@ -1,8 +1,8 @@ - - + + - - - - - - + - - - - - - - - - + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - - - - - + + + + + + + + + - + - + - + - + - + - - - - - - - - - - + + + + - - + + + + - - + + + + - - + + + + + + + + + + + + - + - + - + - + - + - + - - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/tricontour.png b/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/tricontour.png index 97cfed8225bc..b71eaf6d9a86 100644 Binary files a/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/tricontour.png and b/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/tricontour.png differ diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index 18a6a896fd83..ca4cb2d46207 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -55,7 +55,8 @@ def test_bar3d_notshaded(): fig.canvas.draw() -@image_comparison(baseline_images=['contour3d'], remove_text=True) +@image_comparison(baseline_images=['contour3d'], + remove_text=True, style='mpl20') def test_contour3d(): fig = plt.figure() ax = fig.gca(projection='3d')