Skip to content

Commit 14b47ba

Browse files
committed
More cleanups following PR comments.
1 parent 04062b6 commit 14b47ba

File tree

10 files changed

+38
-59
lines changed

10 files changed

+38
-59
lines changed

doc/api/api_changes/code_removal.rst

+6
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ favor of the synonym ``"auto"``.
3535

3636
The ``shading`` kwarg to ``pcolor`` has been removed. Set ``edgecolors``
3737
appropriately instead.
38+
39+
Removed internal functions
40+
--------------------------
41+
42+
The ``matplotlib.backends.backend_ps.seq_allequal`` function has been removed.
43+
Use ``np.array_equal`` instead.

examples/misc/multiprocess.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,15 @@ def terminate(self):
2828
def poll_draw(self):
2929

3030
def call_back():
31-
while True:
32-
if not self.pipe.poll():
33-
break
34-
31+
while self.pipe.poll():
3532
command = self.pipe.recv()
36-
3733
if command is None:
3834
self.terminate()
3935
return False
40-
4136
else:
4237
self.x.append(command[0])
4338
self.y.append(command[1])
4439
self.ax.plot(self.x, self.y, 'ro')
45-
4640
self.fig.canvas.draw()
4741
return True
4842

lib/matplotlib/__init__.py

+7-22
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import distutils.version
108108
from itertools import chain
109109

110+
from collections import MutableMapping
110111
import io
111112
import inspect
112113
import locale
@@ -870,7 +871,7 @@ def matplotlib_fname():
870871
_obsolete_set))
871872

872873

873-
class RcParams(dict):
874+
class RcParams(MutableMapping, dict):
874875

875876
"""
876877
A dictionary object including validation
@@ -891,8 +892,7 @@ class RcParams(dict):
891892

892893
# validate values on the way in
893894
def __init__(self, *args, **kwargs):
894-
for k, v in six.iteritems(dict(*args, **kwargs)):
895-
self[k] = v
895+
self.update(*args, **kwargs)
896896

897897
def __setitem__(self, key, val):
898898
try:
@@ -942,16 +942,6 @@ def __getitem__(self, key):
942942
else:
943943
return val
944944

945-
# http://stackoverflow.com/questions/2390827
946-
# (how-to-properly-subclass-dict-and-override-get-set)
947-
# the default dict `update` does not use __setitem__
948-
# so rcParams.update(...) (such as in seaborn) side-steps
949-
# all of the validation over-ride update to force
950-
# through __setitem__
951-
def update(self, *args, **kwargs):
952-
for k, v in six.iteritems(dict(*args, **kwargs)):
953-
self[k] = v
954-
955945
def __repr__(self):
956946
import pprint
957947
class_name = self.__class__.__name__
@@ -965,17 +955,12 @@ def __str__(self):
965955
return '\n'.join('{0}: {1}'.format(k, v)
966956
for k, v in sorted(self.items()))
967957

968-
def keys(self):
969-
"""
970-
Return sorted list of keys.
971-
"""
972-
return sorted(self)
973-
974-
def values(self):
958+
def __iter__(self):
975959
"""
976-
Return values in order of sorted keys.
960+
Yield sorted list of keys.
977961
"""
978-
return [self[k] for k in self]
962+
for k in sorted(dict.__iter__(self)):
963+
yield k
979964

980965
def find_all(self, pattern):
981966
"""

lib/matplotlib/axes/_base.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import itertools
1010
import warnings
1111
import math
12-
from operator import itemgetter
12+
from operator import attrgetter
1313

1414
import numpy as np
1515

@@ -396,9 +396,7 @@ def _plot_args(self, tup, kwargs):
396396
return ret
397397

398398
def _grab_next_args(self, *args, **kwargs):
399-
while True:
400-
if not args:
401-
return
399+
while args:
402400
this, args = args[:2], args[2:]
403401
if args and is_string_like(args[0]):
404402
this += args[0],
@@ -2357,18 +2355,18 @@ def draw(self, renderer=None, inframe=False):
23572355
if not self.figure.canvas.is_saving():
23582356
artists = [a for a in artists
23592357
if not a.get_animated() or a in self.images]
2360-
artists = sorted(artists, key=lambda artist: artist.get_zorder())
2358+
artists = sorted(artists, key=attrgetter('zorder'))
23612359

23622360
# rasterize artists with negative zorder
23632361
# if the minimum zorder is negative, start rasterization
23642362
rasterization_zorder = self._rasterization_zorder
23652363
if (rasterization_zorder is not None and
2366-
artists and artists[0].get_zorder() < rasterization_zorder):
2364+
artists and artists[0].zorder < rasterization_zorder):
23672365
renderer.start_rasterizing()
23682366
artists_rasterized = [a for a in artists
2369-
if a.get_zorder() < rasterization_zorder]
2367+
if a.zorder < rasterization_zorder]
23702368
artists = [a for a in artists
2371-
if a.get_zorder() >= rasterization_zorder]
2369+
if a.zorder >= rasterization_zorder]
23722370
else:
23732371
artists_rasterized = []
23742372

lib/matplotlib/axis.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,9 @@ def _update_ticks(self, renderer):
952952

953953
interval = self.get_view_interval()
954954
tick_tups = list(self.iter_ticks())
955-
if self._smart_bounds:
955+
if self._smart_bounds and tick_tups:
956956
# handle inverted limits
957-
view_low, view_high = min(interval), max(interval)
957+
view_low, view_high = sorted(interval)
958958
data_low, data_high = sorted(self.get_data_interval())
959959
locs = np.sort([ti[1] for ti in tick_tups])
960960
if data_low <= view_low:
@@ -963,7 +963,7 @@ def _update_ticks(self, renderer):
963963
else:
964964
# data stops within view, take best tick
965965
good_locs = locs[locs <= data_low]
966-
if len(good_locs) > 0:
966+
if len(good_locs):
967967
# last tick prior or equal to first data point
968968
ilow = good_locs[-1]
969969
else:
@@ -975,7 +975,7 @@ def _update_ticks(self, renderer):
975975
else:
976976
# data stops within view, take best tick
977977
good_locs = locs[locs >= data_high]
978-
if len(good_locs) > 0:
978+
if len(good_locs):
979979
# first tick after or equal to last data point
980980
ihigh = good_locs[0]
981981
else:

lib/matplotlib/backends/backend_gdk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
3636
_debug = False
3737

3838
# Image formats that this backend supports - for FileChooser and print_figure()
39-
IMAGE_FORMAT = sorted(['eps', 'jpg', 'png', 'ps', 'svg'] + ['bmp']) # , 'raw', 'rgb']
39+
IMAGE_FORMAT = sorted(['bmp', 'eps', 'jpg', 'png', 'ps', 'svg']) # 'raw', 'rgb'
4040
IMAGE_FORMAT_DEFAULT = 'png'
4141

4242

lib/matplotlib/backends/backend_ps.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ def quote_ps_string(s):
170170
return s.decode('ascii')
171171

172172

173-
seq_allequal = np.array_equal
174-
175-
176173
class RendererPS(RendererBase):
177174
"""
178175
The renderer handles all the drawing primitives using a graphics
@@ -256,7 +253,7 @@ def set_linecap(self, linecap, store=1):
256253
def set_linedash(self, offset, seq, store=1):
257254
if self.linedash is not None:
258255
oldo, oldseq = self.linedash
259-
if seq_allequal(seq, oldseq) and oldo == offset:
256+
if np.array_equal(seq, oldseq) and oldo == offset:
260257
return
261258

262259
if seq is not None and len(seq):

lib/matplotlib/cm.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ def _generate_cmap(name, lutsize):
8585
# spectral/spectral_r when this module is imported.
8686
with _warnings.catch_warnings():
8787
_warnings.simplefilter("ignore")
88-
# Generate the reversed specifications ...
89-
for cmapname, spec in list(six.iteritems(datad)):
90-
datad[cmapname + '_r'] = _reverse_cmap_spec(spec)
91-
92-
# Precache the cmaps with ``lutsize = LUTSIZE`` ...
88+
# Generate the reversed specifications (all at once, to avoid
89+
# modify-when-iterating).
90+
datad.update({cmapname + '_r': _reverse_cmap_spec(spec)
91+
for cmapname, spec in six.iteritems(datad)})
9392

93+
# Precache the cmaps with ``lutsize = LUTSIZE``.
9494
# Also add the reversed ones added in the section above:
9595
for cmapname in datad:
9696
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)

lib/matplotlib/table.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def add_cell(self, row, col, *args, **kwargs):
287287
cell.set_transform(self.get_transform())
288288

289289
cell.set_clip_on(False)
290-
self._cells[(row, col)] = cell
290+
self._cells[row, col] = cell
291291
self.stale = True
292292

293293
@property
@@ -327,9 +327,9 @@ def _get_grid_bbox(self, renderer):
327327
"""Get a bbox, in axes co-ordinates for the cells.
328328
329329
Only include those in the range (0,0) to (maxRow, maxCol)"""
330-
boxes = [self._cells[pos].get_window_extent(renderer)
331-
for pos in self._cells if pos[0] >= 0 and pos[1] >= 0]
332-
330+
boxes = [cell.get_window_extent(renderer)
331+
for (row, col), cell in six.iteritems(self._cells)
332+
if row >= 0 and col >= 0]
333333
bbox = Bbox.union(boxes)
334334
return bbox.inverse_transformed(self.get_transform())
335335

@@ -362,7 +362,6 @@ def get_window_extent(self, renderer):
362362
'Return the bounding box of the table in window coords'
363363
boxes = [cell.get_window_extent(renderer)
364364
for cell in six.itervalues(self._cells)]
365-
366365
return Bbox.union(boxes)
367366

368367
def _do_cell_alignment(self):

lib/mpl_toolkits/mplot3d/proj3d.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ def proj_transform_vec(vec, M):
134134
def proj_transform_vec_clip(vec, M):
135135
vecw = np.dot(M, vec)
136136
w = vecw[3]
137-
# clip here..
138-
txs, tys, tzs = vecw[0]/w, vecw[1]/w, vecw[2]/w
139-
tis = (vecw[0] >= 0) & (vecw[0] <= 1) & (vecw[1] >= 0) & (vecw[1] <= 1)
137+
# clip here.
138+
txs, tys, tzs = vecw[0] / w, vecw[1] / w, vecw[2] / w
139+
tis = (0 <= vecw[0]) & (vecw[0] <= 1) & (0 <= vecw[1]) & (vecw[1] <= 1)
140140
if np.any(tis):
141141
tis = vecw[1] < 1
142142
return txs, tys, tzs, tis

0 commit comments

Comments
 (0)