From 72e581a55673ffaebc90983782887aa416d9b629 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 13 Apr 2017 20:15:25 -0700 Subject: [PATCH] More robust check for numpoints in legend_handler. --- lib/matplotlib/legend_handler.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/legend_handler.py b/lib/matplotlib/legend_handler.py index 67706de0486c..0b16a2ff8f93 100644 --- a/lib/matplotlib/legend_handler.py +++ b/lib/matplotlib/legend_handler.py @@ -149,15 +149,14 @@ def get_xdata(self, legend, xdescent, ydescent, width, height, fontsize): numpoints = self.get_numpoints(legend) if numpoints > 1: - # we put some pad here to compensate the size of the - # marker + # we put some pad here to compensate the size of the marker pad = self._marker_pad * fontsize xdata = np.linspace(-xdescent + pad, -xdescent + width - pad, numpoints) xdata_marker = xdata - elif numpoints == 1: - xdata = np.linspace(-xdescent, -xdescent+width, 2) + else: + xdata = np.linspace(-xdescent, -xdescent + width, 2) xdata_marker = [-xdescent + 0.5 * width] return xdata, xdata_marker