Skip to content

Misc. cleanups. #12956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions examples/text_labels_and_annotations/arrow_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,16 @@ 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

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
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that's really better in this context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this form as it's immediately clear that you're not dropping anything from args, i.e. that single line also asserts that args has length 1. (Yes, it's redundant with the line just above, but I still think it helps the readability.)

else:
x, y = args

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/style/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 4 additions & 10 deletions lib/matplotlib/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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