diff --git a/examples/misc/multipage_pdf.py b/examples/misc/multipage_pdf.py index 9b49f1d8644f..9986237c7f29 100644 --- a/examples/misc/multipage_pdf.py +++ b/examples/misc/multipage_pdf.py @@ -47,7 +47,7 @@ # We can also set the file's metadata via the PdfPages object: d = pdf.infodict() d['Title'] = 'Multipage PDF Example' - d['Author'] = u'Jouni K. Sepp\xe4nen' + d['Author'] = 'Jouni K. Sepp\xe4nen' d['Subject'] = 'How to create a multipage pdf file and set its metadata' d['Keywords'] = 'PdfPages multipage keywords author title subject' d['CreationDate'] = datetime.datetime(2009, 11, 13) diff --git a/examples/pyplots/text_commands.py b/examples/pyplots/text_commands.py index a074f4ca395d..4885a0051925 100644 --- a/examples/pyplots/text_commands.py +++ b/examples/pyplots/text_commands.py @@ -5,6 +5,7 @@ Plotting text of many different kinds. """ + import matplotlib.pyplot as plt fig = plt.figure() @@ -22,7 +23,7 @@ ax.text(2, 6, r'an equation: $E=mc^2$', fontsize=15) -ax.text(3, 2, u'unicode: Institut f\374r Festk\366rperphysik') +ax.text(3, 2, 'unicode: Institut f\374r Festk\366rperphysik') ax.text(0.95, 0.01, 'colored text in axes coords', verticalalignment='bottom', horizontalalignment='right', diff --git a/lib/matplotlib/sphinxext/tests/tinypages/conf.py b/lib/matplotlib/sphinxext/tests/tinypages/conf.py index d2d26c18eceb..970a3c5a4d45 100644 --- a/lib/matplotlib/sphinxext/tests/tinypages/conf.py +++ b/lib/matplotlib/sphinxext/tests/tinypages/conf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # tinypages documentation build configuration file, created by # sphinx-quickstart on Tue Mar 18 11:58:34 2014. # @@ -46,8 +44,8 @@ master_doc = 'index' # General information about the project. -project = u'tinypages' -copyright = u'2014, Matplotlib developers' +project = 'tinypages' +copyright = '2014, Matplotlib developers' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -202,8 +200,8 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'tinypages.tex', u'tinypages Documentation', - u'Matplotlib developers', 'manual'), + ('index', 'tinypages.tex', 'tinypages Documentation', + 'Matplotlib developers', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -232,8 +230,8 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'tinypages', u'tinypages Documentation', - [u'Matplotlib developers'], 1) + ('index', 'tinypages', 'tinypages Documentation', + ['Matplotlib developers'], 1) ] # If true, show URL addresses after external links. @@ -246,8 +244,8 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'tinypages', u'tinypages Documentation', - u'Matplotlib developers', 'tinypages', 'One line description of project.', + ('index', 'tinypages', 'tinypages Documentation', + 'Matplotlib developers', 'tinypages', 'One line description of project.', 'Miscellaneous'), ] diff --git a/lib/matplotlib/testing/determinism.py b/lib/matplotlib/testing/determinism.py index 614544ce28ec..f43706ea5beb 100644 --- a/lib/matplotlib/testing/determinism.py +++ b/lib/matplotlib/testing/determinism.py @@ -2,16 +2,11 @@ Provides utilities to test output reproducibility. """ -from __future__ import (absolute_import, division, print_function, - unicode_literals) - -import six - import io import os import re +import subprocess import sys -from subprocess import check_output import pytest @@ -34,11 +29,11 @@ def _determinism_save(objects='mhi', format="pdf", usetex=False): # use different markers... ax1 = fig.add_subplot(1, 6, 1) x = range(10) - ax1.plot(x, [1] * 10, marker=u'D') - ax1.plot(x, [2] * 10, marker=u'x') - ax1.plot(x, [3] * 10, marker=u'^') - ax1.plot(x, [4] * 10, marker=u'H') - ax1.plot(x, [5] * 10, marker=u'v') + ax1.plot(x, [1] * 10, marker='D') + ax1.plot(x, [2] * 10, marker='x') + ax1.plot(x, [3] * 10, marker='^') + ax1.plot(x, [4] * 10, marker='H') + ax1.plot(x, [5] * 10, marker='v') if 'h' in objects: # also use different hatch patterns @@ -63,13 +58,8 @@ def _determinism_save(objects='mhi', format="pdf", usetex=False): x = range(5) fig.add_subplot(1, 6, 6).plot(x, x) - if six.PY2 and format == 'ps': - stdout = io.StringIO() - else: - stdout = getattr(sys.stdout, 'buffer', sys.stdout) + stdout = getattr(sys.stdout, 'buffer', sys.stdout) fig.savefig(stdout, format=format) - if six.PY2 and format == 'ps': - sys.stdout.write(stdout.getvalue()) # Restores SOURCE_DATE_EPOCH if sde is None: @@ -94,14 +84,14 @@ def _determinism_check(objects='mhi', format="pdf", usetex=False): """ plots = [] for i in range(3): - result = check_output([sys.executable, '-R', '-c', - 'import matplotlib; ' - 'matplotlib._called_from_pytest = True; ' - 'matplotlib.use(%r); ' - 'from matplotlib.testing.determinism ' - 'import _determinism_save;' - '_determinism_save(%r,%r,%r)' - % (format, objects, format, usetex)]) + result = subprocess.check_output([ + sys.executable, '-R', '-c', + 'import matplotlib; ' + 'matplotlib._called_from_pytest = True; ' + 'matplotlib.use(%r); ' + 'from matplotlib.testing.determinism import _determinism_save;' + '_determinism_save(%r, %r, %r)' + % (format, objects, format, usetex)]) plots.append(result) for p in plots[1:]: if usetex: @@ -128,14 +118,14 @@ def _determinism_source_date_epoch(format, string, keyword=b"CreationDate"): a string to look at when searching for the timestamp in the document (used in case the test fails). """ - buff = check_output([sys.executable, '-R', '-c', - 'import matplotlib; ' - 'matplotlib._called_from_pytest = True; ' - 'matplotlib.use(%r); ' - 'from matplotlib.testing.determinism ' - 'import _determinism_save;' - '_determinism_save(%r,%r)' - % (format, "", format)]) + buff = subprocess.check_output([ + sys.executable, '-R', '-c', + 'import matplotlib; ' + 'matplotlib._called_from_pytest = True; ' + 'matplotlib.use(%r); ' + 'from matplotlib.testing.determinism import _determinism_save;' + '_determinism_save(%r, %r)' + % (format, "", format)]) find_keyword = re.compile(b".*" + keyword + b".*") key = find_keyword.search(buff) if key: diff --git a/lib/matplotlib/tests/test_afm.py b/lib/matplotlib/tests/test_afm.py index d4cfce2c61e6..eef807b1d3df 100644 --- a/lib/matplotlib/tests/test_afm.py +++ b/lib/matplotlib/tests/test_afm.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- - -from __future__ import absolute_import, division, print_function -from six import BytesIO +from io import BytesIO import matplotlib.afm as afm @@ -33,7 +30,7 @@ def test_nonascii_str(): # This tests that we also decode bytes as utf-8 properly. # Else, font files with non ascii characters fail to load. - inp_str = u"привет" + inp_str = "привет" byte_str = inp_str.encode("utf8") ret = afm._to_str(byte_str) diff --git a/lib/matplotlib/tests/test_animation.py b/lib/matplotlib/tests/test_animation.py index 31543da9d32f..ed3f5919f02c 100644 --- a/lib/matplotlib/tests/test_animation.py +++ b/lib/matplotlib/tests/test_animation.py @@ -1,7 +1,3 @@ -from __future__ import absolute_import, division, print_function - -import six - import sys import tempfile @@ -205,14 +201,14 @@ def test_movie_writer_registry(): assert len(animation.writers._registered) > 0 animation.writers.list() # resets dirty state assert not animation.writers._dirty - mpl.rcParams['animation.ffmpeg_path'] = u"not_available_ever_xxxx" + mpl.rcParams['animation.ffmpeg_path'] = "not_available_ever_xxxx" assert animation.writers._dirty animation.writers.list() # resets assert not animation.writers._dirty assert not animation.writers.is_available("ffmpeg") # something which is guaranteed to be available in path # and exits immediately - bin = u"true" if sys.platform != 'win32' else u"where" + bin = "true" if sys.platform != 'win32' else "where" mpl.rcParams['animation.ffmpeg_path'] = bin assert animation.writers._dirty animation.writers.list() # resets diff --git a/lib/matplotlib/tests/test_backend_pgf.py b/lib/matplotlib/tests/test_backend_pgf.py index b42d99e23a61..1a3d943cf3da 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -1,6 +1,3 @@ -# -*- encoding: utf-8 -*- -from __future__ import absolute_import, division, print_function - import os import shutil import subprocess @@ -73,7 +70,7 @@ def create_figure(): # text and typesetting plt.plot([0.9], [0.5], "ro", markersize=3) - plt.text(0.9, 0.5, u'unicode (ü, °, µ) and math ($\\mu_i = x_i^2$)', + plt.text(0.9, 0.5, 'unicode (ü, °, µ) and math ($\\mu_i = x_i^2$)', ha='right', fontsize=20) plt.ylabel('sans-serif, blue, $\\frac{\\sqrt{x}}{y^2}$..', family='sans-serif', color='blue') diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index 8bf6e7dde38e..8768b2669ceb 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -1,13 +1,8 @@ -# -*- coding: utf-8 -*- - -from __future__ import absolute_import, division, print_function - import io import re import numpy as np import pytest -import six import matplotlib import matplotlib.pyplot as plt @@ -31,13 +26,14 @@ @pytest.mark.flaky(reruns=3) @pytest.mark.parametrize('format, use_log, rcParams', [ ('ps', False, {}), - needs_ghostscript(('ps', False, {'ps.usedistiller': 'ghostscript'})), - needs_usetex(needs_ghostscript(('ps', False, {'text.latex.unicode': True, - 'text.usetex': True}))), + needs_ghostscript( + ('ps', False, {'ps.usedistiller': 'ghostscript'})), + needs_usetex(needs_ghostscript( + ('ps', False, {'text.latex.unicode': True, 'text.usetex': True}))), ('eps', False, {}), ('eps', True, {'ps.useafm': True}), - needs_usetex(needs_ghostscript(('eps', False, {'text.latex.unicode': True, - 'text.usetex': True}))), + needs_usetex(needs_ghostscript( + ('eps', False, {'text.latex.unicode': True, 'text.usetex': True}))), ], ids=[ 'ps', 'ps with distiller', @@ -50,35 +46,25 @@ def test_savefig_to_stringio(format, use_log, rcParams): matplotlib.rcParams.update(rcParams) fig, ax = plt.subplots() - buffers = [ - six.moves.StringIO(), - io.StringIO(), - io.BytesIO()] - - if use_log: - ax.set_yscale('log') - - ax.plot([1, 2], [1, 2]) - ax.set_title(u"Déjà vu") - for buffer in buffers: - fig.savefig(buffer, format=format) - - values = [x.getvalue() for x in buffers] - - if six.PY3: - values = [ - values[0].encode('ascii'), - values[1].encode('ascii'), - values[2]] - - # Remove comments from the output. This includes things that - # could change from run to run, such as the time. - values = [re.sub(b'%%.*?\n', b'', x) for x in values] - - assert values[0] == values[1] - assert values[1] == values[2].replace(b'\r\n', b'\n') - for buffer in buffers: - buffer.close() + + with io.StringIO() as s_buf, io.BytesIO() as b_buf: + + if use_log: + ax.set_yscale('log') + + ax.plot([1, 2], [1, 2]) + ax.set_title("Déjà vu") + fig.savefig(s_buf, format=format) + fig.savefig(b_buf, format=format) + + s_val = s_buf.getvalue().encode('ascii') + b_val = b_buf.getvalue() + + # Remove comments from the output. This includes things that could + # change from run to run, such as the time. + s_val, b_val = [re.sub(b'%%.*?\n', b'', x) for x in [s_val, b_val]] + + assert s_val == b_val.replace(b'\r\n', b'\n') def test_patheffects(): diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index db6d596f57e7..9484d10a663e 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -106,7 +106,7 @@ def test_various_labels(): fig = plt.figure() ax = fig.add_subplot(121) ax.plot(np.arange(4), 'o', label=1) - ax.plot(np.linspace(4, 4.1), 'o', label=u'D\xe9velopp\xe9s') + ax.plot(np.linspace(4, 4.1), 'o', label='Développés') ax.plot(np.arange(4, 1, -1), 'o', label='__nolegend__') ax.legend(numpoints=1, loc=0) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 32206a0c6168..1738adb93034 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -1,15 +1,13 @@ -from __future__ import absolute_import, division, print_function +import warnings -from numpy.testing import assert_almost_equal import numpy as np +from numpy.testing import assert_almost_equal import pytest import matplotlib import matplotlib.pyplot as plt import matplotlib.ticker as mticker -import warnings - class TestMaxNLocator(object): basic_data = [ @@ -578,7 +576,7 @@ class TestEngFormatter(object): (-0.0, ('0', '0', '0.00')), (-0, ('0', '0', '0.00')), (0, ('0', '0', '0.00')), - (1.23456789e-6, (u'1.23457 \u03bc', u'1 \u03bc', u'1.23 \u03bc')), + (1.23456789e-6, ('1.23457 \u03bc', '1 \u03bc', '1.23 \u03bc')), (0.123456789, ('123.457 m', '123 m', '123.46 m')), (0.1, ('100 m', '100 m', '100.00 m')), (1, ('1', '1', '1.00')), diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index ca6f544ada4d..4a5b01406da6 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -9,12 +9,7 @@ wide and tall you want your Axes to be to accommodate your widget. """ -from __future__ import (absolute_import, division, print_function, - unicode_literals) - import copy -import six -from six.moves import zip import numpy as np from matplotlib import rcParams @@ -221,7 +216,7 @@ def _release(self, event): return if event.inaxes != self.ax: return - for cid, func in six.iteritems(self.observers): + for cid, func in self.observers.items(): func(event) def _motion(self, event): @@ -438,7 +433,7 @@ def set_val(self, val): self.val = val if not self.eventson: return - for cid, func in six.iteritems(self.observers): + for cid, func in self.observers.items(): func(val) def on_changed(self, func): @@ -602,7 +597,7 @@ def set_active(self, index): if not self.eventson: return - for cid, func in six.iteritems(self.observers): + for cid, func in self.observers.items(): func(self.labels[index].get_text()) def get_status(self): @@ -684,7 +679,7 @@ def __init__(self, ax, label, initial='', self.DIST_FROM_LEFT = .05 - self.params_to_disable = [key for key in rcParams if u'keymap' in key] + self.params_to_disable = [key for key in rcParams if 'keymap' in key] self.text = initial self.label = ax.text(-label_pad, 0.5, label, @@ -759,7 +754,7 @@ def _rendercursor(self): self.ax.figure.canvas.draw() def _notify_submit_observers(self): - for cid, func in six.iteritems(self.submit_observers): + for cid, func in self.submit_observers.items(): func(self.text) def _release(self, event): @@ -818,7 +813,7 @@ def set_val(self, val): self._notify_submit_observers() def _notify_change_observers(self): - for cid, func in six.iteritems(self.change_observers): + for cid, func in self.change_observers.items(): func(self.text) def begin_typing(self, x): @@ -1051,7 +1046,7 @@ def set_active(self, index): if not self.eventson: return - for cid, func in six.iteritems(self.observers): + for cid, func in self.observers.items(): func(self.labels[index].get_text()) def on_clicked(self, func): diff --git a/tutorials/text/text_intro.py b/tutorials/text/text_intro.py index 54896236779d..ccf3911e65d0 100644 --- a/tutorials/text/text_intro.py +++ b/tutorials/text/text_intro.py @@ -80,7 +80,7 @@ ax.text(2, 6, r'an equation: $E=mc^2$', fontsize=15) -ax.text(3, 2, u'unicode: Institut für Festkörperphysik') +ax.text(3, 2, 'unicode: Institut für Festkörperphysik') ax.text(0.95, 0.01, 'colored text in axes coords', verticalalignment='bottom', horizontalalignment='right',