diff --git a/examples/text_labels_and_annotations/arrow_demo.py b/examples/text_labels_and_annotations/arrow_demo.py index c76bf4e5962d..2f6b5933b007 100644 --- a/examples/text_labels_and_annotations/arrow_demo.py +++ b/examples/text_labels_and_annotations/arrow_demo.py @@ -147,10 +147,7 @@ def do_fontsize(k): if normalize_data: # find maximum value for rates, i.e. where keys are 2 chars long - max_val = 0 - for k, v in data.items(): - if len(k) == 2: - max_val = max(max_val, v) + max_val = max((v for k, v in data.items() if len(k) == 2), default=0) # divide rates by max val, multiply by arrow scale factor for k, v in data.items(): data[k] = v / max_val * sf @@ -158,8 +155,8 @@ def do_fontsize(k): def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor): # set the length of the arrow if display == 'length': - length = max_head_length + data[pair] / sf * (max_arrow_length - - max_head_length) + length = (max_head_length + + data[pair] / sf * (max_arrow_length - max_head_length)) else: length = max_arrow_length # set the transparency of the arrow diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index aa1b8bdd5fc6..8e2818f098e1 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -1896,7 +1896,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None): fontsize = prop.get_size_in_points() dvifile = texmanager.make_dvi(s, fontsize) with dviread.Dvi(dvifile, 72) as dvi: - page = next(iter(dvi)) + page, = dvi # Gather font information and do some setup for combining # characters into strings. The variable seq will contain a diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 0166439bb4d2..149c5c09238d 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -657,7 +657,7 @@ def set_data(self, *args): *args : (N, 2) array or two 1D arrays """ if len(args) == 1: - x, y = args[0] + (x, y), = args else: x, y = args @@ -763,8 +763,8 @@ def draw(self, renderer): self.ind_offset = 0 # Needed for contains() method. if self._subslice and self.axes: x0, x1 = self.axes.get_xbound() - i0, = self._x_filled.searchsorted([x0], 'left') - i1, = self._x_filled.searchsorted([x1], 'right') + i0 = self._x_filled.searchsorted(x0, 'left') + i1 = self._x_filled.searchsorted(x1, 'right') subslice = slice(max(i0 - 1, 0), i1 + 1) self.ind_offset = subslice.start self._transform_path(subslice) diff --git a/lib/matplotlib/style/core.py b/lib/matplotlib/style/core.py index 05a7e660b161..715d479e1199 100644 --- a/lib/matplotlib/style/core.py +++ b/lib/matplotlib/style/core.py @@ -178,7 +178,7 @@ def iter_style_files(style_dir): if is_style_file(filename): match = STYLE_FILE_PATTERN.match(filename) path = os.path.abspath(os.path.join(style_dir, path)) - yield path, match.groups()[0] + yield path, match.group(1) def read_style_directory(style_dir): diff --git a/lib/matplotlib/table.py b/lib/matplotlib/table.py index 6640abfecc20..8fb0ed206d09 100644 --- a/lib/matplotlib/table.py +++ b/lib/matplotlib/table.py @@ -518,17 +518,11 @@ def auto_set_column_width(self, col): def _auto_set_column_width(self, col, renderer): """Automatically set width for column.""" - cells = [key for key in self._cells if key[1] == col] - - # find max width - width = 0 - for cell in cells: - c = self._cells[cell] - width = max(c.get_required_width(renderer), width) - - # Now set the widths + cells = [cell for key, cell in self._cells.items() if key[1] == col] + max_width = max((cell.get_required_width(renderer) for cell in cells), + default=0) for cell in cells: - self._cells[cell].set_width(width) + cell.set_width(max_width) def auto_set_font_size(self, value=True): """ Automatically set font size. """ diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index 3841be4ecad4..98dcb8bb5ca9 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -463,6 +463,6 @@ def get_text_width_height_descent(self, tex, fontsize, renderer=None): # use dviread. It sometimes returns a wrong descent. dvifile = self.make_dvi(tex, fontsize) with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi: - page = next(iter(dvi)) + page, = dvi # A total height (including the descent) needs to be returned. return page.width, page.height + page.descent, page.descent