Skip to content

Documentation fails to build with Python 3 #2281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions doc/pyplots/text_commands.py
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
2 changes: 1 addition & 1 deletion doc/pyplots/whats_new_99_spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions doc/users/image_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<http://www.pythonware.com/products/pil/>`_). Natively, matplotlib
only supports PNG images. The commands shown below fall back on PIL
if the native read fails.
Expand Down Expand Up @@ -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
<http://www.luminous-landscape.com/tutorials/bit-depth.shtml>`_.

Each inner list represents a pixel. Here, with an RGB image, there
Expand Down Expand Up @@ -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
<http://www.scipy.org/Tentative_NumPy_Tutorial>`_.

.. sourcecode:: ipython
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/animation_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions examples/pylab_examples/boxplot_demo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
6 changes: 3 additions & 3 deletions examples/pylab_examples/filledmarker_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions examples/pylab_examples/multiple_yaxis_with_spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down