Skip to content

Commit acbe206

Browse files
mdboomddale
authored andcommitted
Able to produce simple_plot.py!!!
svn path=/branches/py3k/; revision=8561
1 parent 192f67e commit acbe206

File tree

16 files changed

+82
-75
lines changed

16 files changed

+82
-75
lines changed

examples/pylab_examples/simple_plot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
ylabel('voltage (mV)')
99
title('About as simple as it gets, folks')
1010
grid(True)
11+
savefig("test.png")
1112
show()

lib/matplotlib/artist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def set_clip_path(self, path, transform=None):
485485
:class:`~matplotlib.transforms.Transform`) |
486486
:class:`~matplotlib.patches.Patch` | None ]
487487
"""
488-
from patches import Patch, Rectangle
488+
from matplotlib.patches import Patch, Rectangle
489489

490490
success = False
491491
if transform is None:

lib/matplotlib/axes.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import division, generators
2-
import math, sys, warnings, datetime, new
2+
import math, sys, warnings, datetime
33
from operator import itemgetter
44
import itertools
55

@@ -8468,9 +8468,15 @@ def subplot_class_factory(axes_class=None):
84688468

84698469
new_class = _subplot_classes.get(axes_class)
84708470
if new_class is None:
8471-
new_class = new.classobj("%sSubplot" % (axes_class.__name__),
8472-
(SubplotBase, axes_class),
8473-
{'_axes_class': axes_class})
8471+
if sys.hexversion >= 0x03000000:
8472+
new_class = type("%sSubplot" % (axes_class.__name__),
8473+
(SubplotBase, axes_class),
8474+
{'_axes_class': axes_class})
8475+
else:
8476+
import new
8477+
new_class = new.classobj("%sSubplot" % (axes_class.__name__),
8478+
(SubplotBase, axes_class),
8479+
{'_axes_class': axes_class})
84748480
_subplot_classes[axes_class] = new_class
84758481

84768482
return new_class

lib/matplotlib/backends/backend_agg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from matplotlib.path import Path
3636
from matplotlib.transforms import Bbox, BboxBase
3737

38-
from _backend_agg import RendererAgg as _RendererAgg
38+
from matplotlib.backends._backend_agg import RendererAgg as _RendererAgg
3939
from matplotlib import _png
4040

4141
backend_version = 'v2.2'
@@ -436,7 +436,7 @@ def print_raw(self, filename_or_obj, *args, **kwargs):
436436
original_dpi = renderer.dpi
437437
renderer.dpi = self.figure.dpi
438438
if is_string_like(filename_or_obj):
439-
filename_or_obj = file(filename_or_obj, 'wb')
439+
filename_or_obj = open(filename_or_obj, 'wb')
440440
renderer._renderer.write_rgba(filename_or_obj)
441441
renderer.dpi = original_dpi
442442
print_rgba = print_raw
@@ -447,7 +447,7 @@ def print_png(self, filename_or_obj, *args, **kwargs):
447447
original_dpi = renderer.dpi
448448
renderer.dpi = self.figure.dpi
449449
if is_string_like(filename_or_obj):
450-
filename_or_obj = file(filename_or_obj, 'wb')
450+
filename_or_obj = open(filename_or_obj, 'wb')
451451
_png.write_png(renderer._renderer.buffer_rgba(0, 0),
452452
renderer.width, renderer.height,
453453
filename_or_obj, self.figure.dpi)

lib/matplotlib/backends/tkagg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _tkagg
1+
from matplotlib import _tkagg
22
import Tkinter as Tk
33

44
def blit(photoimage, aggimage, bbox=None, colormode=1):

lib/matplotlib/docstring.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
from matplotlib import cbook
2+
import sys
3+
import types
24

35
class Substitution(object):
46
"""
57
A decorator to take a function's docstring and perform string
68
substitution on it.
7-
9+
810
This decorator should be robust even if func.__doc__ is None
911
(for example, if -OO was passed to the interpreter)
10-
12+
1113
Usage: construct a docstring.Substitution with a sequence or
1214
dictionary suitable for performing substitution; then
1315
decorate a suitable function with the constructed object. e.g.
14-
16+
1517
sub_author_name = Substitution(author='Jason')
16-
18+
1719
@sub_author_name
1820
def some_function(x):
1921
"%(author)s wrote this function"
20-
22+
2123
# note that some_function.__doc__ is now "Jason wrote this function"
22-
24+
2325
One can also use positional arguments.
24-
26+
2527
sub_first_last_names = Substitution('Edgar Allen', 'Poe')
26-
28+
2729
@sub_first_last_names
2830
def some_function(x):
2931
"%s %s wrote the Raven"
@@ -56,16 +58,16 @@ class Appender(object):
5658
"""
5759
A function decorator that will append an addendum to the docstring
5860
of the target function.
59-
61+
6062
This decorator should be robust even if func.__doc__ is None
6163
(for example, if -OO was passed to the interpreter).
62-
64+
6365
Usage: construct a docstring.Appender with a string to be joined to
6466
the original docstring. An optional 'join' parameter may be supplied
6567
which will be used to join the docstring and addendum. e.g.
66-
68+
6769
add_copyright = Appender("Copyright (c) 2009", join='\n')
68-
70+
6971
@add_copyright
7072
def my_dog(has='fleas'):
7173
"This docstring will have a copyright below"
@@ -100,6 +102,8 @@ def do_copy(target):
100102
def dedent_interpd(func):
101103
"""A special case of the interpd that first performs a dedent on
102104
the incoming docstring"""
105+
if isinstance(func, types.MethodType) and sys.hexversion <= 0x03000000:
106+
func = func.im_func
103107
return interpd(dedent(func))
104108

105109
def copy_dedent(source):

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from artist import Artist, allow_rasterization
1818
from axes import Axes, SubplotBase, subplot_class_factory
1919
from cbook import flatten, allequal, Stack, iterable, is_string_like
20-
import _image
20+
from matplotlib import _image
2121
import colorbar as cbar
2222
from image import FigureImage
2323
from matplotlib import rcParams

lib/matplotlib/font_manager.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,12 @@ def OSXFontDirectory():
235235
within them.
236236
"""
237237
fontpaths = []
238-
def add(arg,directory,files):
239-
fontpaths.append(directory)
240238

241239
for fontdir in OSXFontDirectories:
242240
try:
243241
if os.path.isdir(fontdir):
244-
os.path.walk(fontdir, add, None)
242+
for root, dirs, files in os.walk(fontdir):
243+
fontpaths.append(root)
245244
except (IOError, OSError, TypeError, ValueError):
246245
pass
247246
return fontpaths
@@ -274,13 +273,12 @@ def x11FontDirectory():
274273
within them.
275274
"""
276275
fontpaths = []
277-
def add(arg,directory,files):
278-
fontpaths.append(directory)
279276

280277
for fontdir in X11FontDirectories:
281278
try:
282279
if os.path.isdir(fontdir):
283-
os.path.walk(fontdir, add, None)
280+
for root, dirs, files in os.walk(fontdir):
281+
fontpaths.append(root)
284282
except (IOError, OSError, TypeError, ValueError):
285283
pass
286284
return fontpaths
@@ -304,6 +302,7 @@ def get_fontconfig_fonts(fontext='ttf'):
304302
return fontfiles
305303

306304
if pipe.returncode == 0:
305+
output = str(output)
307306
for line in output.split('\n'):
308307
fname = line.split(':')[0]
309308
if (os.path.splitext(fname)[1][1:] in fontext and
@@ -945,7 +944,8 @@ def pickle_dump(data, filename):
945944
Equivalent to pickle.dump(data, open(filename, 'w'))
946945
but closes the file to prevent filehandle leakage.
947946
"""
948-
fh = open(filename, 'w')
947+
fh = open(filename, 'wb')
948+
print data
949949
try:
950950
pickle.dump(data, fh)
951951
finally:
@@ -956,7 +956,7 @@ def pickle_load(filename):
956956
Equivalent to pickle.load(open(filename, 'r'))
957957
but closes the file to prevent filehandle leakage.
958958
"""
959-
fh = open(filename, 'r')
959+
fh = open(filename, 'rb')
960960
try:
961961
data = pickle.load(fh)
962962
finally:
@@ -975,7 +975,7 @@ class FontManager:
975975
# Increment this version number whenever the font cache data
976976
# format or behavior has changed and requires a existing font
977977
# cache files to be rebuilt.
978-
__version__ = 7
978+
__version__ = 8
979979

980980
def __init__(self, size=None, weight='normal'):
981981
self._version = self.__version__
@@ -1337,6 +1337,19 @@ def findfont(prop, fontext='ttf'):
13371337
return result
13381338

13391339
else:
1340+
if sys.hexversion >= 0x03000000:
1341+
_fmcache = os.path.join(get_configdir(), 'fontList.py3k.cache')
1342+
else:
1343+
_fmcache = os.path.join(get_configdir(), 'fontList.py3k.cache')
1344+
1345+
fontManager = None
1346+
1347+
def _rebuild():
1348+
global fontManager
1349+
fontManager = FontManager()
1350+
pickle_dump(fontManager, _fmcache)
1351+
verbose.report("generated new fontManager")
1352+
13401353
try:
13411354
fontManager = pickle_load(_fmcache)
13421355
if (not hasattr(fontManager, '_version') or

lib/matplotlib/lines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1823,4 +1823,4 @@ def onpick(self, event):
18231823

18241824
# You can not set the docstring of an instancemethod,
18251825
# but you can on the underlying function. Go figure.
1826-
docstring.dedent_interpd(Line2D.__init__.im_func)
1826+
docstring.dedent_interpd(Line2D.__init__)

lib/matplotlib/mlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
ma = np.ma
149149
from matplotlib import verbose
150150

151-
import matplotlib.nxutils as nxutils
152151
import matplotlib.cbook as cbook
153152
from matplotlib import docstring
154153

@@ -2964,6 +2963,7 @@ def inside_poly(points, verts):
29642963
Return value is a sequence of indices into points for the points
29652964
that are inside the polygon.
29662965
"""
2966+
# PY3KTODO: Reimplement in terms of _path module
29672967
res, = np.nonzero(nxutils.points_inside_poly(points, verts))
29682968
return res
29692969

0 commit comments

Comments
 (0)