diff --git a/doc/pyplots/text_commands.py b/doc/pyplots/text_commands.py index 93b2fcd80308..92f40b60b9ca 100644 --- a/doc/pyplots/text_commands.py +++ b/doc/pyplots/text_commands.py @@ -16,7 +16,7 @@ ax.text(2, 6, r'an equation: $E=mc^2$', fontsize=15) -ax.text(3, 2, unicode('unicode: Institut f\374r Festk\366rperphysik', 'latin-1')) +ax.text(3, 2, u'unicode: Institut f\374r Festk\366rperphysik') ax.text(0.95, 0.01, 'colored text in axes coords', verticalalignment='bottom', horizontalalignment='right', 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/plotting/colormaps/Lfunction.py b/doc/users/plotting/colormaps/Lfunction.py index dadf4de457de..c94a8be4b45a 100644 --- a/doc/users/plotting/colormaps/Lfunction.py +++ b/doc/users/plotting/colormaps/Lfunction.py @@ -3,7 +3,7 @@ with the binary matplotlib colormap, too. Trying to show the difference between adding blackness to a color at different rates. ''' - +from __future__ import print_function import numpy as np import matplotlib.pyplot as plt import colorconv as color @@ -39,10 +39,10 @@ # Alter successive rows with more black k = 1 -for i in xrange(red.shape[1]): +for i in range(red.shape[1]): # more blackness is closer to 0 than one, and in first column of LAB lab_add[0,i,0] = lab_add[0,i,0] - 10*i - print i,k + print(i,k) if i != 0: lab_geometric[0,i,0] = lab_geometric[0,i,0] - 10*k k *= 2 @@ -57,15 +57,15 @@ fig = plt.figure() k = 1 -for i in xrange(red.shape[1]): +for i in range(red.shape[1]): # LHS: additive ax1 = fig.add_subplot(nrows,2,i*2+1, axisbg=tuple(rgb_add[0,i,:])) - print tuple(lab_add[0,i,:])#, tuple(rgb_add[0,i,:]) + print(tuple(lab_add[0,i,:]))#, tuple(rgb_add[0,i,:]) # RHS: multiplicative ax2 = fig.add_subplot(nrows,2,i*2+2, axisbg=tuple(rgb_geometric[0,i,:])) - print tuple(lab_geometric[0,i,:])#, tuple(rgb_geometric[0,i,:]) + print(tuple(lab_geometric[0,i,:]))#, tuple(rgb_geometric[0,i,:]) # ylabels if i!=0: @@ -117,16 +117,16 @@ k = 1 di = 8 I0 = 5 -for i in xrange(nrows): +for i in range(nrows): # Do more blackness via increasing indices rgb_add[:,i,:] = rgb[:,i*di+I0,:] if i != 0: - print i*di+I0, di*k+I0, (I0**(1./3)+i*di**(1./3))**3 + print(i*di+I0, di*k+I0, (I0**(1./3)+i*di**(1./3))**3) rgb_geometric[:,i,:] = rgb[:,I0+di*k,:] k *= 2 elif i==0: - print i*di+I0, I0, (I0**(1./3)+i*di**(1./3))**3 + print(i*di+I0, I0, (I0**(1./3)+i*di**(1./3))**3) rgb_geometric[:,i,:] = rgb[:,I0,:] lab_add = color.rgb2lab(rgb_add) @@ -134,7 +134,7 @@ fig = plt.figure() k = 1 -for i in xrange(nrows): +for i in range(nrows): # LHS: additive ax1 = fig.add_subplot(nrows,ncols,i*2+1, axisbg=tuple(rgb_add[0,i,:])) diff --git a/doc/users/plotting/colormaps/lightness.py b/doc/users/plotting/colormaps/lightness.py index fb97500d0cbc..15f93d29779d 100644 --- a/doc/users/plotting/colormaps/lightness.py +++ b/doc/users/plotting/colormaps/lightness.py @@ -58,7 +58,7 @@ fig = plt.figure(figsize=(11.5,4*nsubplots)) - for i, subplot in enumerate(xrange(nsubplots)): + for i, subplot in enumerate(range(nsubplots)): locs = [] # locations for text labels diff --git a/doc/users/plotting/examples/demo_gridspec06.py b/doc/users/plotting/examples/demo_gridspec06.py index ead2029af251..e1fbaf5c5f99 100644 --- a/doc/users/plotting/examples/demo_gridspec06.py +++ b/doc/users/plotting/examples/demo_gridspec06.py @@ -23,7 +23,7 @@ def squiggle_xy(a, b, c, d, i=np.arange(0.0, 2*np.pi, 0.05)): # gridspec inside gridspec outer_grid = gridspec.GridSpec(4, 4, wspace=0.0, hspace=0.0) -for i in xrange(16): +for i in range(16): inner_grid = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=outer_grid[i], wspace=0.0, hspace=0.0) a, b = int(i/4)+1,i%4+1 diff --git a/examples/api/skewt.py b/examples/api/skewt.py index ce9e23fef157..ba1d23b6c9e6 100644 --- a/examples/api/skewt.py +++ b/examples/api/skewt.py @@ -146,7 +146,7 @@ def _set_lim_and_transforms(self): # Now make a simple example using the custom projection. from matplotlib.ticker import ScalarFormatter, MultipleLocator import matplotlib.pyplot as plt - from StringIO import StringIO + from six import StringIO import numpy as np # Some examples data diff --git a/examples/lines_bars_and_markers/marker_reference.py b/examples/lines_bars_and_markers/marker_reference.py index 81bd3977ae4e..ad7db0e89023 100644 --- a/examples/lines_bars_and_markers/marker_reference.py +++ b/examples/lines_bars_and_markers/marker_reference.py @@ -1,6 +1,7 @@ """ Reference for filled- and unfilled-marker types included with Matplotlib. """ +from six import iteritems import numpy as np import matplotlib.pyplot as plt from matplotlib.lines import Line2D @@ -32,9 +33,14 @@ def split_list(a_list): fig, axes = plt.subplots(ncols=2) # Filter out filled markers and marker settings that do nothing. -unfilled_markers = [m for m, func in Line2D.markers.iteritems() +# We use iteritems from six to make sure that we get an iterator +# in both python 2 and 3 +unfilled_markers = [m for m, func in iteritems(Line2D.markers) if func != 'nothing' and m not in Line2D.filled_markers] -unfilled_markers = sorted(unfilled_markers)[::-1] # Reverse-sort for pretty +# Reverse-sort for pretty. We use our own sort key which is essentially +# a python3 compatible reimplementation of python2 sort. +unfilled_markers = sorted(unfilled_markers, + key=lambda x: (str(type(x)), str(x)))[::-1] for ax, markers in zip(axes, split_list(unfilled_markers)): for y, marker in enumerate(markers): ax.text(-0.5, y, nice_repr(marker), **text_style) diff --git a/examples/pylab_examples/animation_demo.py b/examples/pylab_examples/animation_demo.py index f294a189f75f..a8048d357b1c 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 8249c689110f..e90c00f8fdda 100644 --- a/examples/pylab_examples/boxplot_demo2.py +++ b/examples/pylab_examples/boxplot_demo2.py @@ -57,7 +57,7 @@ # Now fill the boxes with desired colors boxColors = ['darkkhaki', 'royalblue'] numBoxes = numDists*2 -medians = range(numBoxes) +medians = list(range(numBoxes)) for i in range(numBoxes): box = bp['boxes'][i] boxX = [] @@ -65,7 +65,7 @@ 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/logo.py b/examples/pylab_examples/logo.py index 436135cf7fa9..03cb060d18d2 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 98532d31b047..fde330ec5528 100644 --- a/examples/pylab_examples/multiple_yaxis_with_spines.py +++ b/examples/pylab_examples/multiple_yaxis_with_spines.py @@ -4,7 +4,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()