diff --git a/doc/conf.py b/doc/conf.py index 4fd5209eed89..5b918af5899b 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -11,6 +11,7 @@ # All configuration values have a default value; values that are commented out # serve to show the default value. +from distutils import version import os import sys import sphinx @@ -44,7 +45,7 @@ autosummary_generate = True -if sphinx.__version__ >= 1.1: +if version.LooseVersion(sphinx.__version__) >= version.LooseVersion('1.1'): autodoc_docstring_signature = True # Add any paths that contain templates here, relative to this directory. diff --git a/doc/pyplots/text_commands.py b/doc/pyplots/text_commands.py index 93b2fcd80308..20431d2500f6 100644 --- a/doc/pyplots/text_commands.py +++ b/doc/pyplots/text_commands.py @@ -1,6 +1,11 @@ # -*- coding: utf-8 -*- import matplotlib.pyplot as plt +# Make this example compatible with Python 2 and 3 +import sys +if sys.version_info[0] == 3: + unicode = str + fig = plt.figure() fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold') diff --git a/doc/pyplots/whats_new_99_spines.py b/doc/pyplots/whats_new_99_spines.py index 1ee80a9e708e..83c4edf5d07f 100644 --- a/doc/pyplots/whats_new_99_spines.py +++ b/doc/pyplots/whats_new_99_spines.py @@ -4,7 +4,7 @@ def adjust_spines(ax,spines): - for loc, spine in ax.spines.iteritems(): + for loc, spine in ax.spines.items(): if loc in spines: spine.set_position(('outward',10)) # outward by 10 points else: diff --git a/doc/users/image_tutorial.rst b/doc/users/image_tutorial.rst index dbc74d66ea79..3fd74060a895 100644 --- a/doc/users/image_tutorial.rst +++ b/doc/users/image_tutorial.rst @@ -40,7 +40,7 @@ examples, if you use the -pylab method, you can skip the "mpimg." and Importing image data into Numpy arrays =============================================== -Plotting image data is supported by the Python Image Library (`PIL +Plotting image data is supported by the Python Image Library (`PIL `_). Natively, matplotlib only supports PNG images. The commands shown below fall back on PIL if the native read fails. @@ -122,7 +122,7 @@ reading/writing for any format other than PNG is limited to uint8 data. Why 8 bits? Most displays can only render 8 bits per channel worth of color gradation. Why can they only render 8 bits/channel? Because that's about all the human eye can see. More here (from a -photography standpoint): `Luminous Landscape bit depth tutorial +photography standpoint): `Luminous Landscape bit depth tutorial `_. Each inner list represents a pixel. Here, with an RGB image, there @@ -179,7 +179,7 @@ channel of our data: In [6]: lum_img = img[:,:,0] -This is array slicing. You can read more in the `Numpy tutorial +This is array slicing. You can read more in the `Numpy tutorial `_. .. sourcecode:: ipython @@ -336,7 +336,7 @@ and the computer has to draw in pixels to fill that space. .. sourcecode:: ipython - In [8]: import Image + In [8]: from PIL import Image In [9]: img = Image.open('stinkbug.png') # Open image as PIL image object In [10]: rsize = img.resize((img.size[0]/10,img.size[1]/10)) # Use PIL to resize In [11]: rsizeArr = np.asarray(rsize) # Get array back @@ -347,7 +347,7 @@ and the computer has to draw in pixels to fill that space. import matplotlib.pyplot as plt import matplotlib.image as mpimg import numpy as np - import Image + from PIL import Image img = Image.open('../_static/stinkbug.png') # opens the file using PIL - it's not an array yet rsize = img.resize((img.size[0]/10,img.size[1]/10)) # resize the image rsizeArr = np.asarray(rsize) @@ -368,7 +368,7 @@ Let's try some others: import matplotlib.pyplot as plt import matplotlib.image as mpimg import numpy as np - import Image + from PIL import Image img = Image.open('../_static/stinkbug.png') # opens the file using PIL - it's not an array yet rsize = img.resize((img.size[0]/10,img.size[1]/10)) # resize the image rsizeArr = np.asarray(rsize) @@ -385,7 +385,7 @@ Let's try some others: import matplotlib.pyplot as plt import matplotlib.image as mpimg import numpy as np - import Image + from PIL import Image img = Image.open('../_static/stinkbug.png') # opens the file using PIL - it's not an array yet rsize = img.resize((img.size[0]/10,img.size[1]/10)) # resize the image rsizeArr = np.asarray(rsize) diff --git a/examples/pylab_examples/animation_demo.py b/examples/pylab_examples/animation_demo.py index 13a5649ee202..175c9c68ca71 100644 --- a/examples/pylab_examples/animation_demo.py +++ b/examples/pylab_examples/animation_demo.py @@ -13,7 +13,7 @@ y = np.arange(5) z = x * y[:,np.newaxis] -for i in xrange(5): +for i in range(5): if i==0: p = plt.imshow(z) fig = plt.gcf() diff --git a/examples/pylab_examples/boxplot_demo2.py b/examples/pylab_examples/boxplot_demo2.py index 5a5b8a4e1c27..2eac09fe32c6 100644 --- a/examples/pylab_examples/boxplot_demo2.py +++ b/examples/pylab_examples/boxplot_demo2.py @@ -57,15 +57,15 @@ # Now fill the boxes with desired colors boxColors = ['darkkhaki','royalblue'] numBoxes = numDists*2 -medians = range(numBoxes) -for i in range(numBoxes): +medians = list(range(numBoxes)) +for i in medians: box = bp['boxes'][i] boxX = [] boxY = [] for j in range(5): boxX.append(box.get_xdata()[j]) boxY.append(box.get_ydata()[j]) - boxCoords = zip(boxX,boxY) + boxCoords = list(zip(boxX,boxY)) # Alternate between Dark Khaki and Royal Blue k = i % 2 boxPolygon = Polygon(boxCoords, facecolor=boxColors[k]) diff --git a/examples/pylab_examples/filledmarker_demo.py b/examples/pylab_examples/filledmarker_demo.py index b4f001512ffb..6692b330e17a 100644 --- a/examples/pylab_examples/filledmarker_demo.py +++ b/examples/pylab_examples/filledmarker_demo.py @@ -14,13 +14,13 @@ f = plt.figure() f.text(.5,.95, "marker = %r" % marker, ha='center') for i,fs in enumerate(mlines.Line2D.fillStyles): - color = colors.next() + color = next(colors) ax = f.add_subplot(121) ax.plot(2*(4-i)+y, c=color, marker=marker, - markersize=20, - fillstyle=fs, + markersize=20, + fillstyle=fs, label=fs) ax.legend(loc=2) ax.set_title('fillstyle') diff --git a/examples/pylab_examples/logo.py b/examples/pylab_examples/logo.py index ae62ee5d9643..6b3932d4b783 100755 --- a/examples/pylab_examples/logo.py +++ b/examples/pylab_examples/logo.py @@ -9,7 +9,7 @@ datafile = cbook.get_sample_data('membrane.dat', asfileobj=False) print('loading', datafile) -x = 1000*0.1*fromstring(file(datafile, 'rb').read(), float32) +x = 1000*0.1*fromstring(open(datafile, 'rb').read(), float32) # 0.0005 is the sample interval t = 0.0005*arange(len(x)) figure(1, figsize=(7,1), dpi=100) diff --git a/examples/pylab_examples/multiple_yaxis_with_spines.py b/examples/pylab_examples/multiple_yaxis_with_spines.py index 3b13b770feff..5a0d71b07883 100644 --- a/examples/pylab_examples/multiple_yaxis_with_spines.py +++ b/examples/pylab_examples/multiple_yaxis_with_spines.py @@ -3,7 +3,7 @@ def make_patch_spines_invisible(ax): ax.set_frame_on(True) ax.patch.set_visible(False) - for sp in ax.spines.itervalues(): + for sp in ax.spines.values(): sp.set_visible(False) fig, host = plt.subplots() @@ -15,8 +15,8 @@ def make_patch_spines_invisible(ax): # Offset the right spine of par2. The ticks and label have already been # placed on the right by twinx above. par2.spines["right"].set_position(("axes", 1.2)) -# Having been created by twinx, par2 has its frame off, so the line of its -# detached spine is invisible. First, activate the frame but make the patch +# Having been created by twinx, par2 has its frame off, so the line of its +# detached spine is invisible. First, activate the frame but make the patch # and spines invisible. make_patch_spines_invisible(par2) # Second, show the right spine. diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index b825e83507f4..e22630e733ca 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -773,13 +773,13 @@ def get_sample_data(fname, asfileobj=True): path = os.path.join(root, fname) if asfileobj: - if (os.path.splitext(fname)[-1].lower() in - ('.csv', '.xrc', '.txt')): + base, ext = os.path.splitext(fname) + ext = ext.lower() + if (ext in ('.csv', '.xrc', '.txt')): mode = 'r' else: mode = 'rb' - base, ext = os.path.splitext(fname) if ext == '.gz': return gzip.open(path, mode) else: