8000 Merge remote-tracking branch 'upstream/v1.2.x' · matplotlib/matplotlib@1485757 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1485757

Browse files
committed
Merge remote-tracking branch 'upstream/v1.2.x'
2 parents 1e72892 + 0ae5762 commit 1485757

File tree

9 files changed

+79
-64
lines changed

9 files changed

+79
-64
lines changed

doc/faq/howto_faq.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,8 @@ Cite Matplotlib
757757

758758
If you want to refer to matplotlib in a publication, you can use
759759
"Matplotlib: A 2D Graphics Environment" by J. D. Hunter In Computing
760-
in Science & Engineering, Vol. 9, No. 3. (2007), pp. 90-95 (see `IEEE
761-
Xplore
762-
<http://ieeexplore.ieee.org/xpl/login.jsp?tp=&arnumber=4160265&url=http%3A%2F%2Fieeexplore.ieee.org%2Fxpls%2Fabs_all.jsp%3Farnumber%3D4160265>`_)::
760+
in Science & Engineering, Vol. 9, No. 3. (2007), pp. 90-95 (see `here
761+
<http://dx.doi.org/10.1109/MCSE.2007.55>`_)::
763762

764763
@article{Hunter:2007,
765764
Address = {10662 LOS VAQUEROS CIRCLE, PO BOX 3014, LOS ALAMITOS, CA 90720-1314 USA},

examples/units/basic_units.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ def __get__(self, obj, objtype=None):
1717
return self.proxy_type(self.fn_name, obj)
1818

1919

20-
class TaggedValueMeta(type):
21-
def __init__(self, name, bases):
22-
for fn_name in self._proxies.keys():
20+
class TaggedValueMeta (type):
21+
def __init__(cls, name, bases, dict):
22+
for fn_name in cls._proxies.keys():
2323
try:
24-
dummy = getattr(self, fn_name)
24+
dummy = getattr(cls, fn_name)
2525
except AttributeError:
26-
setattr(self, fn_name,
27-
ProxyDelegate(fn_name, self._proxies[fn_name]))
26+
setattr(cls, fn_name,
27+
ProxyDelegate(fn_name, cls._proxies[fn_name]))
2828

2929

3030
class PassThroughProxy(object):
@@ -189,7 +189,7 @@ def get_unit(self):
189189
return self.unit
190190

191191

192-
TaggedValue = TaggedValueMeta('TaggedValue', (_TaggedValue, ))
192+
TaggedValue = TaggedValueMeta('TaggedValue', (_TaggedValue, ), {})
193193

194194

195195
class BasicUnit(object):

lib/matplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
This is an object-orient plotting library.
2+
This is an object-oriented plotting library.
33
44
A procedural interface is provided by the companion pyplot module,
55
which may be imported directly, e.g::

lib/matplotlib/axes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import matplotlib.collections as mcoll
1717
import matplotlib.colors as mcolors
1818
import matplotlib.contour as mcontour
19+
import matplotlib.dates as _ # <-registers a date unit converter
1920
from matplotlib import docstring
2021
import matplotlib.font_manager as font_manager
2122
import matplotlib.image as mimage

lib/matplotlib/colors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,8 @@ def __call__(self, x, clip=None):
10561056
for i, b in enumerate(self.boundaries):
10571057
iret[xx >= b] = i
10581058
if self._interp:
1059-
iret *= float(self.Ncmap - 1) / (self.N - 2)
1060-
iret = iret.astype(np.int16)
1059+
scalefac = float(self.Ncmap - 1) / (self.N - 2)
1060+
iret = (iret * scalefac).astype(np.int16)
10611061
iret[xx < self.vmin] = -1
10621062
iret[xx >= self.vmax] = self.Ncmap
10631063
ret = ma.array(iret, mask=mask)
Loading

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,8 @@ def test_stackplot():
822822
y3 = 3.0 * x + 2
823823
ax = fig.add_subplot(1, 1, 1)
824824
ax.stackplot(x, y1, y2, y3)
825+
ax.set_xlim((0, 10))
826+
ax.set_ylim((0, 70))
825827

826828
@image_comparison(baseline_images=['boxplot'])
827829
def test_boxplot():

lib/matplotlib/tests/test_colors.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,17 @@ def test_colormap_endian():
2323
#print(anative.dtype.isnative, aforeign.dtype.isnative)
2424
assert_array_equal(cmap(anative), cmap(aforeign))
2525

26+
def test_BoundaryNorm():
27+
"""
28+
Github issue #1258: interpolation was failing with numpy
29+
1.7 pre-release.
30+
"""
31+
# TODO: expand this into a more general test of BoundaryNorm.
32+
boundaries = [0, 1.1, 2.2]
33+
vals = [-1, 0, 2, 2.2, 4]
34+
expected = [-1, 0, 2, 3, 3]
35+
# ncolors != len(boundaries) - 1 triggers interpolation
36+
ncolors = len(boundaries)
37+
bn = mcolors.BoundaryNorm(boundaries, ncolors)
38+
assert_array_equal(bn(vals), expected)
2639

lib/matplotlib/tests/test_pickle.py

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,38 @@
1414
from io import BytesIO
1515

1616

17-
def depth_getter(obj,
18-
current_depth=0,
19-
depth_stack=None,
17+
def depth_getter(obj,
18+
current_depth=0,
19+
depth_stack=None,
2020
nest_info='top level object'):
2121
"""
2222
Returns a dictionary mapping:
23-
23+
2424
id(obj): (shallowest_depth, obj, nest_info)
25-
26-
for the given object (and its subordinates).
27-
28-
This, in conjunction with recursive_pickle, can be used to debug
25+
26+
for the given object (and its subordinates).
27+
28+
This, in conjunction with recursive_pickle, can be used to debug
2929
pickling issues, although finding others is sometimes a case of
3030
trial and error.
31-
31+
3232
"""
3333
if depth_stack is None:
3434
depth_stack = {}
35-
35+
3636
if id(obj) in depth_stack:
3737
stack = depth_stack[id(obj)]
3838
if stack[0] > current_depth:
3939
del depth_stack[id(obj)]
4040
else:
4141
return depth_stack
42-
42+
4343
depth_stack[id(obj)] = (current_depth, obj, nest_info)
44-
44+
4545
if isinstance(obj, (list, tuple)):
4646
for i, item in enumerate(obj):
47-
depth_getter(item, current_depth=current_depth+1,
48-
depth_stack=depth_stack,
47+
depth_getter(item, current_depth=current_depth+1,
48+
depth_stack=depth_stack,
4949
nest_info='list/tuple item #%s in (%s)' % (i, nest_info))
5050
else:
5151
if isinstance(obj, dict):
@@ -58,16 +58,16 @@ def depth_getter(obj,
5858
state = obj.__dict__
5959
else:
6060
state = {}
61-
61+
6262
for key, value in state.iteritems():
63-
depth_getter(value, current_depth=current_depth+1,
64-
depth_stack=depth_stack,
63+
depth_getter(value, current_depth=current_depth+1,
64+
depth_stack=depth_stack,
6565
nest_info='attribute "%s" in (%s)' % (key, nest_info))
66-
66+
6767
# for instancemethod picklability (and some other issues), uncommenting
6868
# the following may be helpful
6969
# print([(name, dobj.__class__) for name, dobj in state.iteritems()], ': ', nest_info, ';', type(obj))
70-
70+
7171
return depth_stack
7272

7373

@@ -76,14 +76,14 @@ def recursive_pickle(top_obj):
7676
Recursively pickle all of the given objects subordinates, starting with
7777
the deepest first. **Very** handy for debugging pickling issues, but
7878
also very slow (as it literally pickles each object in turn).
79-
79+
8080
Handles circular object references gracefully.
81-
81+
8282
"""
8383
objs = depth_getter(top_obj)
8484
# sort by depth then by nest_info
8585
objs = sorted(objs.itervalues(), key=lambda val: (-val[0], val[2]))
86-
86+
8787
for _, obj, location in objs:
8888
# print('trying %s' % location)
8989
try:
@@ -110,90 +110,90 @@ def test_simple():
110110

111111
# recursive_pickle(fig)
112112
pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL)
113-
113+
114114
# ax = plt.subplot(121, projection='hammer')
115115
# recursive_pickle(ax, 'figure')
116116
# pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL)
117117

118118

119-
@image_comparison(baseline_images=['multi_pickle'],
120-
extensions=['png'])
119+
@image_comparison(baseline_images=['multi_pickle'],
120+
extensions=['png'], remove_text=True)
121121
def test_complete():
122122
fig = plt.figure('Figure with a label?', figsize=(10, 6))
123-
123+
124124
plt.suptitle('Can you fit any more in a figure?')
125-
125+
126126
# make some arbitrary data
127127
x, y = np.arange(8), np.arange(10)
128128
data = u = v = np.linspace(0, 10, 80).reshape(10, 8)
129129
v = np.sin(v * -0.6)
130-
130+
131131
plt.subplot(3,3,1)
132132
plt.plot(range(10))
133-
133+
134134
plt.subplot(3, 3, 2)
135135
plt.contourf(data, hatches=['//', 'ooo'])
136136
plt.colorbar()
137-
137+
138138
plt.subplot(3, 3, 3)
139139
plt.pcolormesh(data)
140-
141-
140+
141+
142142
plt.subplot(3, 3, 4)
143143
plt.imshow(data)
144-
144+
145145
plt.subplot(3, 3, 5)
146146
plt.pcolor(data)
147-
147+
148148
plt.subplot(3, 3, 6)
149149
plt.streamplot(x, y, u, v)
150-
150+
151151
plt.subplot(3, 3, 7)
152152
plt.quiver(x, y, u, v)
153-
153+
154154
plt.subplot(3, 3, 8)
155155
plt.scatter(x, x**2, label='$x^2$')
156156
plt.legend(loc='upper left')
157-
157+
158158
plt.subplot(3, 3, 9)
159159
plt.errorbar(x, x * -0.5, xerr=0.2, yerr=0.4)
160-
160+
161161
###### plotting is done, now test its pickle-ability #########
162-
162+
163163
# Uncomment to debug any unpicklable objects. This is slow (~200 seconds).
164164
# recursive_pickle(fig)
165-
165+
166166
result_fh = BytesIO()
167167
pickle.dump(fig, result_fh, pickle.HIGHEST_PROTOCOL)
168-
168+
169169
plt.close('all')
170-
170+
171171
# make doubly sure that there are no figures left
172172
assert_equal(plt._pylab_helpers.Gcf.figs, {})
173-
173+
174174
# wind back the fh and load in the figure
175175
result_fh.seek(0)
176176
fig = pickle.load(result_fh)
177-
177+
178178
# make sure there is now a figure manager
179179
assert_not_equal(plt._pylab_helpers.Gcf.figs, {})
180-
180+
181181
assert_equal(fig.get_label(), 'Figure with a label?')
182-
183-
182+
183+
184184
def test_no_pyplot():
185185
# tests pickle-ability of a figure not created with pyplot
186-
186+
187187
import pickle as p
188188
from matplotlib.backends.backend_pdf import FigureCanvasPdf as fc
189189
from matplotlib.figure import Figure
190-
190+
191191
fig = Figure()
192192
can = fc(fig)
193193
ax = fig.add_subplot(1, 1, 1)
194194
ax.plot([1, 2, 3], [1, 2, 3])
195-
196-
# Uncomment to debug any unpicklable objects. This is slow so is not
195+
196+
# Uncomment to debug any unpicklable objects. This is slow so is not
197197
# uncommented by default.
198198
# recursive_pickle(fig)
199199
pickle.dump(fig, BytesIO(), pickle.HIGHEST_PROTOCOL)

0 commit comments

Comments
 (0)
0