Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove many unused variables. #13932

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
Apr 23, 2019
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
1 change: 0 additions & 1 deletion doc/sphinxext/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def ghuser_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
:param options: Directive options for customization.
:param content: The directive content for customization.
"""
app = inliner.document.settings.env.app
ref = 'https://www.github.com/' + text
node = nodes.reference(rawtext, text, refuri=ref, **options)
return [node], []
Expand Down
7 changes: 2 additions & 5 deletions examples/axes_grid1/demo_axes_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ def demo_simple_grid(fig):
axes_pad=0.05,
label_mode="1",
)

Z, extent = get_demo_image()
for ax in grid:
im = ax.imshow(Z, extent=extent, interpolation="nearest")

# This only affects axes in first column and second row as share_all =
# False.
ax.imshow(Z, extent=extent, interpolation="nearest")
Copy link
Member

Choose a reason for hiding this comment

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

I loosely recall that there was a discussion if examples should have return values even though they are not used.

Advantage: The user sees that this returns an object that can be used further.
Disadvantage: In practical use, you would only define the return value if you actually need it. So the example does not represent how you would use Matplotlib in real life. And it's more cluttered than need be.

Personally, I'm fine with removing.

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 hope no one is reading axes_grid demos to learn about basic mpl concepts such as artists being returned by most calls :)

# This only affects axes in first column and second row as share_all=False.
grid.axes_llc.set_xticks([-2, 0, 2])
grid.axes_llc.set_yticks([-2, 0, 2])

Expand Down
2 changes: 1 addition & 1 deletion examples/axes_grid1/demo_edge_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def demo_bottom_cbar(fig):
im = grid[i].imshow(Z, extent=extent, interpolation="nearest",
cmap=cmaps[i//2])
if i % 2:
cbar = grid.cbar_axes[i//2].colorbar(im)
grid.cbar_axes[i//2].colorbar(im)

for cax in grid.cbar_axes:
cax.toggle_label(True)
Expand Down
13 changes: 6 additions & 7 deletions examples/event_handling/pick_event_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def pick_simple():
line, = ax1.plot(rand(100), 'o', picker=5) # 5 points tolerance

# pick the rectangle
bars = ax2.bar(range(10), rand(10), picker=True)
ax2.bar(range(10), rand(10), picker=True)
for label in ax2.get_xticklabels(): # make the xtick labels pickable
label.set_picker(True)

Expand Down Expand Up @@ -157,18 +157,17 @@ def onpick3(event):
print('onpick3 scatter:', ind, x[ind], y[ind])

fig, ax = plt.subplots()
col = ax.scatter(x, y, 100*s, c, picker=True)
#fig.savefig('pscoll.eps')
ax.scatter(x, y, 100*s, c, picker=True)
fig.canvas.mpl_connect('pick_event', onpick3)


def pick_image():
# picking images (matplotlib.image.AxesImage)
fig, ax = plt.subplots()
im1 = ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True)
im2 = ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True)
im3 = ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True)
im4 = ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True)
ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True)
ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True)
ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True)
ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True)
ax.axis([0, 5, 0, 5])

def onpick4(event):
Expand Down
4 changes: 2 additions & 2 deletions examples/misc/demo_agg_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def filtered_text(ax):
Z = (Z1 - Z2) * 2

# draw
im = ax.imshow(Z, interpolation='bilinear', origin='lower',
cmap=cm.gray, extent=(-3, 3, -2, 2))
ax.imshow(Z, interpolation='bilinear', origin='lower',
cmap=cm.gray, extent=(-3, 3, -2, 2))
levels = np.arange(-1.2, 1.6, 0.2)
CS = ax.contour(Z, levels,
origin='lower',
Expand Down
4 changes: 1 addition & 3 deletions examples/units/basic_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def __get__(self, obj, objtype=None):
class TaggedValueMeta(type):
def __init__(self, name, bases, dict):
for fn_name in self._proxies:
try:
dummy = getattr(self, fn_name)
except AttributeError:
if not hasattr(self, fn_name):
setattr(self, fn_name,
ProxyDelegate(fn_name, self._proxies[fn_name]))

Expand Down
2 changes: 0 additions & 2 deletions examples/widgets/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ def __init__(self, fig, menuitems):
maxw = max(item.labelwidth for item in menuitems)
maxh = max(item.labelheight for item in menuitems)

totalh = self.numitems*maxh + (self.numitems + 1)*2*MenuItem.pady

x0 = 100
y0 = 400

Expand Down
4 changes: 1 addition & 3 deletions lib/matplotlib/axes/_secondary_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,14 @@ def _set_lims(self):
if self._orientation == 'x':
lims = self._parent.get_xlim()
set_lim = self.set_xlim
trans = self.xaxis.get_transform()
if self._orientation == 'y':
lims = self._parent.get_ylim()
set_lim = self.set_ylim
trans = self.yaxis.get_transform()
order = lims[0] < lims[1]
lims = self._functions[0](np.array(lims))
neworder = lims[0] < lims[1]
if neworder != order:
# flip because the transform will take care of the flipping..
# Flip because the transform will take care of the flipping.
lims = lims[::-1]
set_lim(lims)

Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def motion_notify_event(self, widget, event):
if event.is_hint:
t, x, y, state = event.window.get_pointer()
else:
x, y, state = event.x, event.y, event.get_state()
x, y = event.x, event.y

# flipy so y=0 is bottom of canvas
y = self.get_allocation().height - y
Expand Down Expand Up @@ -582,7 +582,8 @@ def configure_subplots(self, button):
toolfig = Figure(figsize=(6, 3))
canvas = self._get_canvas(toolfig)
toolfig.subplots_adjust(top=0.9)
tool = SubplotTool(self.canvas.figure, toolfig)
# Need to keep a reference to the tool.
_tool = SubplotTool(self.canvas.figure, toolfig)

w = int(toolfig.bbox.width)
h = int(toolfig.bbox.height)
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/backends/backend_gtk3agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def blit(self, bbox=None):
bbox = self.figure.bbox

allocation = self.get_allocation()
w, h = allocation.width, allocation.height
x = int(bbox.x0)
y = h - int(bbox.y1)
y = allocation.height - int(bbox.y1)
width = int(bbox.x1) - int(bbox.x0)
height = int(bbox.y1) - int(bbox.y0)

Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/backend_macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def prepare_configure_subplots(self):
toolfig = Figure(figsize=(6, 3))
canvas = FigureCanvasMac(toolfig)
toolfig.subplots_adjust(top=0.9)
tool = SubplotTool(self.canvas.figure, toolfig)
# Need to keep a reference to the tool.
_tool = SubplotTool(self.canvas.figure, toolfig)
return canvas

def set_message(self, message):
Expand Down
9 changes: 2 additions & 7 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,15 +1026,10 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
font = self._get_font(prop)
font.set_text(s, 0.0, flags=LOAD_NO_HINTING)

fontsize = prop.get_size_in_points()

fontfamily = font.family_name
fontstyle = prop.get_style()

attrib = {}
# Must add "px" to workaround a Firefox bug
style['font-size'] = short_float_fmt(fontsize) + 'px'
style['font-family'] = str(fontfamily)
style['font-size'] = short_float_fmt(prop.get_size()) + 'px'
Copy link
Member

Choose a reason for hiding this comment

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

.get_size_in_points and .get_size are methods with identical bodies....

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 know... planning to deprecate get_size_in_points but there are bugger issues with fontproperties anyways.

style['font-family'] = str(font.family_name)
style['font-style'] = prop.get_style().lower()
style['font-weight'] = str(prop.get_weight()).lower()
attrib['style'] = generate_css(style)
Expand Down
4 changes: 1 addition & 3 deletions lib/matplotlib/cbook/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,7 @@ def _make_keyword_only(since, name, func=None):
kwonly = [name for name in names[names.index(name):]
if signature.parameters[name].kind == POK]
func.__signature__ = signature.replace(parameters=[
param.replace(kind=inspect.Parameter.KEYWORD_ONLY)
if param.name in kwonly
else param
param.replace(kind=KWO) if param.name in kwonly else param
for param in signature.parameters.values()])

@functools.wraps(func)
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,6 @@ def get_positions(self):
'''
return an array containing the floating-point values of the positions
'''
segments = self.get_segments()
pos = 0 if self.is_horizontal() else 1
return [segment[0, pos] for segment in self.get_segments()]

Expand Down
15 changes: 4 additions & 11 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,9 @@ def update_ticks(self):
called whenever the tick locator and/or tick formatter changes.
"""
ax = self.ax
# get the locator and formatter. Defaults to
# self.locator if not None..
# Get the locator and formatter; defaults to self.locator if not None.
locator, formatter = self._get_ticker_locator_formatter()
if self.orientation == 'vertical':
long_axis, short_axis = ax.yaxis, ax.xaxis
else:
long_axis, short_axis = ax.xaxis, ax.yaxis

long_axis = ax.yaxis if self.orientation == 'vertical' else ax.xaxis
if self._use_auto_colorbar_locator():
_log.debug('Using auto colorbar locator on colorbar')
_log.debug('locator: %r', locator)
Expand Down Expand Up @@ -643,10 +638,8 @@ def get_ticks(self, minor=False):
"""Return the x ticks as a list of locations."""
if self._manual_tick_data_values is None:
ax = self.ax
if self.orientation == 'vertical':
long_axis, short_axis = ax.yaxis, ax.xaxis
else:
long_axis, short_axis = ax.xaxis, ax.yaxis
long_axis = (
ax.yaxis if self.orientation == 'vertical' else ax.xaxis)
return long_axis.get_majorticklocs()
else:
# We made the axes manually, the old way, and the ylim is 0-1,
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def _fnt_def_real(self, k, c, s, d, a, l):

@_dispatch(247, state=_dvistate.pre, args=('u1', 'u4', 'u4', 'u4', 'u1'))
def _pre(self, i, num, den, mag, k):
comment = self.file.read(k)
self.file.read(k) # comment in the dvi file
if i != 2:
raise ValueError("Unknown dvi format %d" % i)
if num != 25400000 or den != 7227 * 2**16:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ def validate_webagg_address(s):
import socket
try:
socket.inet_aton(s)
except socket.error as e:
except socket.error:
raise ValueError("'webagg.address' is not a valid IP address")
return s
raise ValueError("'webagg.address' is not a valid IP address")
Expand Down
16 changes: 8 additions & 8 deletions lib/matplotlib/sphinxext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def run_code(code, code_path, ns=None, function_name=None):
if function_name is not None:
exec(function_name + "()", ns)

except (Exception, SystemExit) as err:
except (Exception, SystemExit):
raise PlotError(traceback.format_exc())
finally:
os.chdir(pwd)
Expand Down Expand Up @@ -584,11 +584,11 @@ def render_figures(code, code_path, output_dir, output_base, context,
output_dir)
else:
img = ImageFile('%s_%02d' % (output_base, j), output_dir)
for format, dpi in formats:
if out_of_date(code_path, img.filename(format)):
for fmt, dpi in formats:
if out_of_date(code_path, img.filename(fmt)):
all_exists = False
break
img.formats.append(format)
img.formats.append(fmt)

# assume that if we have one, we have them all
if not all_exists:
Expand Down Expand Up @@ -636,12 +636,12 @@ def render_figures(code, code_path, output_dir, output_base, context,
img = ImageFile("%s_%02d_%02d" % (output_base, i, j),
output_dir)
images.append(img)
for format, dpi in formats:
for fmt, dpi in formats:
try:
figman.canvas.figure.savefig(img.filename(format), dpi=dpi)
except Exception as err:
figman.canvas.figure.savefig(img.filename(fmt), dpi=dpi)
except Exception:
raise PlotError(traceback.format_exc())
img.formats.append(format)
img.formats.append(fmt)

results.append((code_piece, images))

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def make_tex(self, tex, fontsize):
else:
try:
fh.write(s.encode('ascii'))
except UnicodeEncodeError as err:
except UnicodeEncodeError:
_log.info("You are using unicode and latex, but have not "
"enabled the 'text.latex.unicode' rcParam.")
raise
Expand Down Expand Up @@ -289,7 +289,7 @@ def make_tex_preview(self, tex, fontsize):
else:
try:
fh.write(s.encode('ascii'))
except UnicodeEncodeError as err:
except UnicodeEncodeError:
_log.info("You are using unicode and latex, but have not "
"enabled the 'text.latex.unicode' rcParam.")
raise
Expand Down
9 changes: 4 additions & 5 deletions lib/matplotlib/textpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def get_glyphs_mathtext(self, prop, s, glyph_map=None,
if char_id not in glyph_map:
font.clear()
font.set_size(self.FONT_SCALE, self.DPI)
glyph = font.load_char(ccode, flags=LOAD_NO_HINTING)
font.load_char(ccode, flags=LOAD_NO_HINTING)
glyph_map_new[char_id] = font.get_path()

xpositions.append(ox)
Expand Down Expand Up @@ -371,9 +371,9 @@ def _get_ps_font_and_encoding(texname):
# FreeType-synthesized charmap but the native ones (we can't
# directly identify it but it's typically an Adobe charmap), and
# directly load the dvi glyph indices using FT_Load_Char/load_char.
for charmap_name, charmap_code in [
("ADOBE_CUSTOM", 1094992451),
("ADOBE_STANDARD", 1094995778),
for charmap_code in [
1094992451, # ADOBE_CUSTOM.
1094995778, # ADOBE_STANDARD.
]:
try:
font.select_charmap(charmap_code)
Expand All @@ -382,7 +382,6 @@ def _get_ps_font_and_encoding(texname):
else:
break
else:
charmap_name = ""
_log.warning("No supported encoding in font (%s).",
font_bunch.filename)
enc = None
Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/axes_grid1/axes_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_size(self, renderer):
l1, l2 = self._axes.get_xlim()
if self._aspect == "axes":
ref_aspect = _get_axes_aspect(self._ref_ax)
aspect = ref_aspect/_get_axes_aspect(self._axes)
aspect = ref_aspect / _get_axes_aspect(self._axes)
else:
aspect = self._aspect

Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/axes_grid1/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def on_changed(m):
cb.set_clim(m.get_clim())
cb.update_bruteforce(m)

cbid = mappable.callbacksSM.connect('changed', on_changed)
mappable.callbacksSM.connect('changed', on_changed)
mappable.colorbar = cb
ax.figure.sca(ax)
return cb
9 changes: 5 additions & 4 deletions lib/mpl_toolkits/axisartist/angle_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ def select_step(v1, v2, nv, hour=False, include_last=True,
cycle = 360.

# for degree
if dv > 1./threshold_factor:
if dv > 1 / threshold_factor:
step, factor = _select_step(dv)
else:
step, factor = select_step_sub(dv*threshold_factor)

factor = factor * threshold_factor

f1, f2, fstep = v1*factor, v2*factor, step/factor
levs = np.arange(np.floor(f1/step), np.ceil(f2/step)+0.5, dtype=int) * step
levs = np.arange(np.floor(v1 * factor / step),
np.ceil(v2 * factor / step) + 0.5,
dtype=int) * step

# n : number of valid levels. If there is a cycle, e.g., [0, 90, 180,
# 270, 360], the grid line needs to be extended from 0 to 360, so
Expand All @@ -128,7 +129,7 @@ def select_step(v1, v2, nv, hour=False, include_last=True,
# we need to check the range of values
# for example, -90 to 90, 0 to 360,

if factor == 1. and levs[-1] >= levs[0]+cycle: # check for cycle
if factor == 1. and levs[-1] >= levs[0] + cycle: # check for cycle
nv = int(cycle / step)
if include_last:
levs = levs[0] + np.arange(0, nv+1, 1) * step
Expand Down
4 changes: 0 additions & 4 deletions lib/mpl_toolkits/axisartist/axis_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,10 +1194,6 @@ def _draw_label2(self, renderer):
if not self.label.get_visible():
return

fontprops = font_manager.FontProperties(
size=rcParams['axes.labelsize'],
weight=rcParams['axes.labelweight'])

if self._ticklabel_add_angle != self._axislabel_add_angle:
if ((self.major_ticks.get_visible()
and not self.major_ticks.get_tick_out())
Expand Down