From a51b70835b87b8a2b8a0dcd528f2c9d8a57aff02 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 19 Feb 2018 00:27:10 -0800 Subject: [PATCH] py3fy examples - Remove future imports, six, encoding cookies. - The pgf_examples don't actually need to be sgskipped. --- examples/api/custom_index_formatter.py | 1 - examples/api/custom_projection_example.py | 6 +----- examples/api/custom_scale_example.py | 7 ++----- examples/api/engineering_formatter.py | 2 +- examples/api/filled_step.py | 5 ++--- examples/api/skewt.py | 2 +- examples/api/watermark_image.py | 1 - examples/color/named_colors.py | 1 - examples/event_handling/close_event.py | 1 - examples/event_handling/coords_demo.py | 1 - .../event_handling/figure_axes_enter_leave.py | 1 - examples/event_handling/ginput_demo_sgskip.py | 1 - .../ginput_manual_clabel_sgskip.py | 1 - examples/event_handling/image_slices_viewer.py | 1 - examples/event_handling/keypress_demo.py | 1 - examples/event_handling/pick_event_demo.py | 1 - examples/event_handling/pipong.py | 1 - examples/event_handling/pong_sgskip.py | 1 - .../images_contours_and_fields/image_demo.py | 1 - .../images_contours_and_fields/layer_images.py | 1 - .../lines_bars_and_markers/marker_reference.py | 6 ++---- .../lines_bars_and_markers/markevery_demo.py | 1 - examples/misc/cursor_demo_sgskip.py | 1 - examples/misc/font_indexing.py | 1 - examples/misc/ftface_props.py | 1 - examples/misc/image_thumbnail_sgskip.py | 1 - examples/misc/load_converter.py | 1 - examples/misc/multiprocess_sgskip.py | 1 - examples/misc/print_stdout_sgskip.py | 6 +----- examples/misc/set_and_get.py | 1 - examples/misc/svg_filter_line.py | 1 - examples/misc/tight_bbox_test.py | 1 - examples/mplot3d/wire3d_animation.py | 1 - examples/pyplots/text_commands.py | 1 - examples/specialty_plots/anscombe.py | 1 - examples/specialty_plots/mri_with_eeg.py | 1 - examples/tests/backend_driver_sgskip.py | 11 +---------- .../accented_text.py | 2 -- .../font_table_ttf_sgskip.py | 5 +---- .../text_labels_and_annotations/legend_demo.py | 7 ++----- .../mathtext_examples.py | 1 - .../rainbow_text.py | 1 - .../stix_fonts_demo.py | 1 - .../text_labels_and_annotations/tex_demo.py | 1 - .../ticks_and_spines/date_index_formatter.py | 1 - examples/units/basic_units.py | 3 +-- .../embedding_in_tk_canvas_sgskip.py | 18 ++++++++---------- .../user_interfaces/embedding_in_tk_sgskip.py | 15 +++++++-------- .../user_interfaces/embedding_in_wx3_sgskip.py | 1 - .../user_interfaces/mpl_with_glade_sgskip.py | 1 - .../user_interfaces/pylab_with_gtk_sgskip.py | 1 - examples/user_interfaces/toolmanager_sgskip.py | 1 - .../{pgf_fonts_sgskip.py => pgf_fonts.py} | 12 ++++-------- examples/userdemo/pgf_preamble_sgskip.py | 12 +++--------- ...gf_texsystem_sgskip.py => pgf_texsystem.py} | 12 ++++-------- examples/widgets/lasso_selector_demo_sgskip.py | 1 - examples/widgets/menu.py | 1 - examples/widgets/rectangle_selector.py | 1 - tutorials/text/pgf.py | 4 ++-- 59 files changed, 43 insertions(+), 133 deletions(-) rename examples/userdemo/{pgf_fonts_sgskip.py => pgf_fonts.py} (78%) rename examples/userdemo/{pgf_texsystem_sgskip.py => pgf_texsystem.py} (77%) diff --git a/examples/api/custom_index_formatter.py b/examples/api/custom_index_formatter.py index 9e117dd91c8d..389fd2e0353e 100644 --- a/examples/api/custom_index_formatter.py +++ b/examples/api/custom_index_formatter.py @@ -7,7 +7,6 @@ to leave out days on which there is no data, i.e. weekends. The example below shows how to use an 'index formatter' to achieve the desired plot """ -from __future__ import print_function import numpy as np import matplotlib.pyplot as plt import matplotlib.cbook as cbook diff --git a/examples/api/custom_projection_example.py b/examples/api/custom_projection_example.py index c446120bb89d..0c7fa720498a 100644 --- a/examples/api/custom_projection_example.py +++ b/examples/api/custom_projection_example.py @@ -3,13 +3,9 @@ Custom projection ================= -Showcase Hammer projection by alleviating many features of -matplotlib. +Showcase Hammer projection by alleviating many features of Matplotlib. """ - -from __future__ import unicode_literals - import matplotlib from matplotlib.axes import Axes from matplotlib.patches import Circle diff --git a/examples/api/custom_scale_example.py b/examples/api/custom_scale_example.py index 574f90ebad80..8150a5b2101c 100644 --- a/examples/api/custom_scale_example.py +++ b/examples/api/custom_scale_example.py @@ -3,13 +3,10 @@ Custom scale ============ -Create a custom scale, by implementing the -scaling use for latitude data in a Mercator Projection. +Create a custom scale, by implementing the scaling use for latitude data in a +Mercator Projection. """ - -from __future__ import unicode_literals - import numpy as np from numpy import ma from matplotlib import scale as mscale diff --git a/examples/api/engineering_formatter.py b/examples/api/engineering_formatter.py index 523cae8090a6..7be2d0fe59cf 100644 --- a/examples/api/engineering_formatter.py +++ b/examples/api/engineering_formatter.py @@ -35,7 +35,7 @@ # `sep` (separator between the number and the prefix/unit). ax1.set_title('SI-prefix only ticklabels, 1-digit precision & ' 'thin space separator') -formatter1 = EngFormatter(places=1, sep=u"\N{THIN SPACE}") # U+2009 +formatter1 = EngFormatter(places=1, sep="\N{THIN SPACE}") # U+2009 ax1.xaxis.set_major_formatter(formatter1) ax1.plot(xs, ys) ax1.set_xlabel('Frequency [Hz]') diff --git a/examples/api/filled_step.py b/examples/api/filled_step.py index 320e48f2a71f..5ab8f42e8951 100644 --- a/examples/api/filled_step.py +++ b/examples/api/filled_step.py @@ -14,7 +14,6 @@ import matplotlib.pyplot as plt import matplotlib.ticker as mticker from cycler import cycler -from six.moves import zip def filled_hist(ax, edges, values, bottoms=None, orientation='v', @@ -150,8 +149,8 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None, labels = itertools.repeat(None) if label_data: - loop_iter = enumerate((stacked_data[lab], lab, s) for lab, s in - zip(labels, sty_cycle)) + loop_iter = enumerate((stacked_data[lab], lab, s) + for lab, s in zip(labels, sty_cycle)) else: loop_iter = enumerate(zip(stacked_data, labels, sty_cycle)) diff --git a/examples/api/skewt.py b/examples/api/skewt.py index 93891f5a2122..aecfce503364 100644 --- a/examples/api/skewt.py +++ b/examples/api/skewt.py @@ -180,10 +180,10 @@ def upper_xlim(self): if __name__ == '__main__': # Now make a simple example using the custom projection. + from io import StringIO from matplotlib.ticker import (MultipleLocator, NullFormatter, ScalarFormatter) import matplotlib.pyplot as plt - from six import StringIO import numpy as np # Some examples data diff --git a/examples/api/watermark_image.py b/examples/api/watermark_image.py index fc057dd2c8ad..bd97f0e1e199 100644 --- a/examples/api/watermark_image.py +++ b/examples/api/watermark_image.py @@ -5,7 +5,6 @@ Use a PNG file as a watermark """ -from __future__ import print_function import numpy as np import matplotlib.cbook as cbook import matplotlib.image as image diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 5fcf95974d1c..7bae6bd9ed59 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -5,7 +5,6 @@ Simple plot example with the named colors and its visual representation. """ -from __future__ import division import matplotlib.pyplot as plt from matplotlib import colors as mcolors diff --git a/examples/event_handling/close_event.py b/examples/event_handling/close_event.py index c7b7fbd56c7d..7613ec45bec9 100644 --- a/examples/event_handling/close_event.py +++ b/examples/event_handling/close_event.py @@ -5,7 +5,6 @@ Example to show connecting events that occur when the figure closes. """ -from __future__ import print_function import matplotlib.pyplot as plt diff --git a/examples/event_handling/coords_demo.py b/examples/event_handling/coords_demo.py index 89ee85fc4d21..249c318cb23e 100644 --- a/examples/event_handling/coords_demo.py +++ b/examples/event_handling/coords_demo.py @@ -6,7 +6,6 @@ An example of how to interact with the plotting canvas by connecting to move and click events """ -from __future__ import print_function import sys import matplotlib.pyplot as plt import numpy as np diff --git a/examples/event_handling/figure_axes_enter_leave.py b/examples/event_handling/figure_axes_enter_leave.py index 703e72058c73..b1c81b6dd5ba 100644 --- a/examples/event_handling/figure_axes_enter_leave.py +++ b/examples/event_handling/figure_axes_enter_leave.py @@ -6,7 +6,6 @@ Illustrate the figure and axes enter and leave events by changing the frame colors on enter and leave """ -from __future__ import print_function import matplotlib.pyplot as plt diff --git a/examples/event_handling/ginput_demo_sgskip.py b/examples/event_handling/ginput_demo_sgskip.py index 77227032b16a..482cdbd5356a 100644 --- a/examples/event_handling/ginput_demo_sgskip.py +++ b/examples/event_handling/ginput_demo_sgskip.py @@ -7,7 +7,6 @@ """ -from __future__ import print_function import matplotlib.pyplot as plt import numpy as np diff --git a/examples/event_handling/ginput_manual_clabel_sgskip.py b/examples/event_handling/ginput_manual_clabel_sgskip.py index 25ee40e4eb23..94642ff8aed5 100644 --- a/examples/event_handling/ginput_manual_clabel_sgskip.py +++ b/examples/event_handling/ginput_manual_clabel_sgskip.py @@ -14,7 +14,6 @@ """ -from __future__ import print_function import time import matplotlib diff --git a/examples/event_handling/image_slices_viewer.py b/examples/event_handling/image_slices_viewer.py index 3409c5ee28b8..2816a802c7f8 100644 --- a/examples/event_handling/image_slices_viewer.py +++ b/examples/event_handling/image_slices_viewer.py @@ -5,7 +5,6 @@ Scroll through 2D image slices of a 3D array. """ -from __future__ import print_function import numpy as np import matplotlib.pyplot as plt diff --git a/examples/event_handling/keypress_demo.py b/examples/event_handling/keypress_demo.py index f0380e11ff3f..149cb1ba3103 100644 --- a/examples/event_handling/keypress_demo.py +++ b/examples/event_handling/keypress_demo.py @@ -5,7 +5,6 @@ Show how to connect to keypress events """ -from __future__ import print_function import sys import numpy as np import matplotlib.pyplot as plt diff --git a/examples/event_handling/pick_event_demo.py b/examples/event_handling/pick_event_demo.py index 22770d33f253..4f2a924e1d23 100644 --- a/examples/event_handling/pick_event_demo.py +++ b/examples/event_handling/pick_event_demo.py @@ -66,7 +66,6 @@ def pick_handler(event): The examples below illustrate each of these methods. """ -from __future__ import print_function import matplotlib.pyplot as plt from matplotlib.lines import Line2D from matplotlib.patches import Rectangle diff --git a/examples/event_handling/pipong.py b/examples/event_handling/pipong.py index c68abac61a7f..c7a925a7db9f 100644 --- a/examples/event_handling/pipong.py +++ b/examples/event_handling/pipong.py @@ -8,7 +8,6 @@ pipong.py was written by Paul Ivanov """ -from __future__ import print_function import numpy as np import matplotlib.pyplot as plt diff --git a/examples/event_handling/pong_sgskip.py b/examples/event_handling/pong_sgskip.py index e07f037c2fda..c7ddb8abe5fb 100644 --- a/examples/event_handling/pong_sgskip.py +++ b/examples/event_handling/pong_sgskip.py @@ -10,7 +10,6 @@ This example requires :download:`pipong.py ` """ -from __future__ import print_function, division import time diff --git a/examples/images_contours_and_fields/image_demo.py b/examples/images_contours_and_fields/image_demo.py index b6d8eaed9ffe..820114cc2be0 100644 --- a/examples/images_contours_and_fields/image_demo.py +++ b/examples/images_contours_and_fields/image_demo.py @@ -10,7 +10,6 @@ functionality of imshow and the many images you can create. """ -from __future__ import print_function import numpy as np import matplotlib.cm as cm diff --git a/examples/images_contours_and_fields/layer_images.py b/examples/images_contours_and_fields/layer_images.py index 725876045924..8209741c02ea 100644 --- a/examples/images_contours_and_fields/layer_images.py +++ b/examples/images_contours_and_fields/layer_images.py @@ -5,7 +5,6 @@ Layer images above one another using alpha blending """ -from __future__ import division import matplotlib.pyplot as plt import numpy as np diff --git a/examples/lines_bars_and_markers/marker_reference.py b/examples/lines_bars_and_markers/marker_reference.py index ee85ce6af535..8b381d1cf051 100644 --- a/examples/lines_bars_and_markers/marker_reference.py +++ b/examples/lines_bars_and_markers/marker_reference.py @@ -5,7 +5,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 @@ -36,9 +36,7 @@ def split_list(a_list): fig, axes = plt.subplots(ncols=2) # Filter out filled markers and marker settings that do nothing. -# 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) +unfilled_markers = [m for m, func in Line2D.markers.items() if func != 'nothing' and m not in Line2D.filled_markers] # Reverse-sort for pretty. We use our own sort key which is essentially # a python3 compatible reimplementation of python2 sort. diff --git a/examples/lines_bars_and_markers/markevery_demo.py b/examples/lines_bars_and_markers/markevery_demo.py index 8141c8d4bb49..62eda10de3bc 100644 --- a/examples/lines_bars_and_markers/markevery_demo.py +++ b/examples/lines_bars_and_markers/markevery_demo.py @@ -20,7 +20,6 @@ """ -from __future__ import division import numpy as np import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec diff --git a/examples/misc/cursor_demo_sgskip.py b/examples/misc/cursor_demo_sgskip.py index a9e3c68c4410..7354b4bb0735 100644 --- a/examples/misc/cursor_demo_sgskip.py +++ b/examples/misc/cursor_demo_sgskip.py @@ -16,7 +16,6 @@ https://github.com/joferkington/mpldatacursor https://github.com/anntzer/mplcursors """ -from __future__ import print_function import matplotlib.pyplot as plt import numpy as np diff --git a/examples/misc/font_indexing.py b/examples/misc/font_indexing.py index 6a1f29260085..7625671968bd 100644 --- a/examples/misc/font_indexing.py +++ b/examples/misc/font_indexing.py @@ -7,7 +7,6 @@ tables relate to one another. Mainly for mpl developers.... """ -from __future__ import print_function import matplotlib from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, KERNING_UNFITTED, KERNING_UNSCALED diff --git a/examples/misc/ftface_props.py b/examples/misc/ftface_props.py index 575af193e7b2..b40a892715ae 100644 --- a/examples/misc/ftface_props.py +++ b/examples/misc/ftface_props.py @@ -8,7 +8,6 @@ individual character metrics, use the Glyph object, as returned by load_char """ -from __future__ import print_function import matplotlib import matplotlib.ft2font as ft diff --git a/examples/misc/image_thumbnail_sgskip.py b/examples/misc/image_thumbnail_sgskip.py index c9d02eb82303..ae82e616743b 100644 --- a/examples/misc/image_thumbnail_sgskip.py +++ b/examples/misc/image_thumbnail_sgskip.py @@ -10,7 +10,6 @@ """ -from __future__ import print_function # build thumbnails of all images in a directory import sys import os diff --git a/examples/misc/load_converter.py b/examples/misc/load_converter.py index 1534a11b5a0f..86a92ab72359 100644 --- a/examples/misc/load_converter.py +++ b/examples/misc/load_converter.py @@ -4,7 +4,6 @@ ============== """ -from __future__ import print_function import numpy as np import matplotlib.pyplot as plt import matplotlib.cbook as cbook diff --git a/examples/misc/multiprocess_sgskip.py b/examples/misc/multiprocess_sgskip.py index 1cf1ecea1593..162b7ba565df 100644 --- a/examples/misc/multiprocess_sgskip.py +++ b/examples/misc/multiprocess_sgskip.py @@ -8,7 +8,6 @@ Written by Robert Cimrman """ -from __future__ import print_function import time import numpy as np diff --git a/examples/misc/print_stdout_sgskip.py b/examples/misc/print_stdout_sgskip.py index da86a2c3cb16..69b0b33616d8 100644 --- a/examples/misc/print_stdout_sgskip.py +++ b/examples/misc/print_stdout_sgskip.py @@ -15,8 +15,4 @@ import matplotlib.pyplot as plt plt.plot([1, 2, 3]) - -if sys.version_info[0] >= 3: - plt.savefig(sys.stdout.buffer) -else: - plt.savefig(sys.stdout) +plt.savefig(sys.stdout.buffer) diff --git a/examples/misc/set_and_get.py b/examples/misc/set_and_get.py index 990fd6c5a3d0..3239d39518b0 100644 --- a/examples/misc/set_and_get.py +++ b/examples/misc/set_and_get.py @@ -67,7 +67,6 @@ these properties will be listed as 'fullname or aliasname'. """ -from __future__ import print_function import matplotlib.pyplot as plt import numpy as np diff --git a/examples/misc/svg_filter_line.py b/examples/misc/svg_filter_line.py index aaef954dd7ba..72c601b6b2f7 100644 --- a/examples/misc/svg_filter_line.py +++ b/examples/misc/svg_filter_line.py @@ -9,7 +9,6 @@ support it. """ -from __future__ import print_function import matplotlib.pyplot as plt import matplotlib.transforms as mtransforms diff --git a/examples/misc/tight_bbox_test.py b/examples/misc/tight_bbox_test.py index 3b4740d427ec..f9dbe3b00f2e 100644 --- a/examples/misc/tight_bbox_test.py +++ b/examples/misc/tight_bbox_test.py @@ -4,7 +4,6 @@ =============== """ -from __future__ import print_function import matplotlib.pyplot as plt import numpy as np diff --git a/examples/mplot3d/wire3d_animation.py b/examples/mplot3d/wire3d_animation.py index 1083f006436f..f52fa46d49b0 100644 --- a/examples/mplot3d/wire3d_animation.py +++ b/examples/mplot3d/wire3d_animation.py @@ -6,7 +6,6 @@ A very simple 'animation' of a 3D plot. See also rotate_axes3d_demo. """ -from __future__ import print_function from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt diff --git a/examples/pyplots/text_commands.py b/examples/pyplots/text_commands.py index 0d4e3d559a45..a074f4ca395d 100644 --- a/examples/pyplots/text_commands.py +++ b/examples/pyplots/text_commands.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ ============= Text Commands diff --git a/examples/specialty_plots/anscombe.py b/examples/specialty_plots/anscombe.py index fd1ecd0bbe58..3f5d98ef914c 100644 --- a/examples/specialty_plots/anscombe.py +++ b/examples/specialty_plots/anscombe.py @@ -4,7 +4,6 @@ ================== """ -from __future__ import print_function """ Edward Tufte uses this example from Anscombe to show 4 datasets of x and y that have the same mean, standard deviation, and regression diff --git a/examples/specialty_plots/mri_with_eeg.py b/examples/specialty_plots/mri_with_eeg.py index 0fd3be3d6eda..26aa36071912 100644 --- a/examples/specialty_plots/mri_with_eeg.py +++ b/examples/specialty_plots/mri_with_eeg.py @@ -7,7 +7,6 @@ histogram and some EEG traces. """ -from __future__ import division, print_function import numpy as np import matplotlib.pyplot as plt diff --git a/examples/tests/backend_driver_sgskip.py b/examples/tests/backend_driver_sgskip.py index 2741283784ce..06c11b0c9399 100644 --- a/examples/tests/backend_driver_sgskip.py +++ b/examples/tests/backend_driver_sgskip.py @@ -21,7 +21,6 @@ switches with a --. """ -from __future__ import print_function, division import os import time import sys @@ -383,16 +382,12 @@ def drive(backend, directories, python=['python'], switches=[]): tmpfile_name = '_tmp_%s.py' % basename tmpfile = open(tmpfile_name, 'w') - future_imports = 'from __future__ import division, print_function' for line in open(fullpath): line_lstrip = line.lstrip() if line_lstrip.startswith("#"): tmpfile.write(line) - elif 'unicode_literals' in line: - future_imports = future_imports + ', unicode_literals' tmpfile.writelines(( - future_imports + '\n', 'import sys\n', 'sys.path.append("%s")\n' % fpath.replace('\\', '\\\\'), 'import matplotlib\n', @@ -402,11 +397,7 @@ def drive(backend, directories, python=['python'], switches=[]): 'numpy.seterr(invalid="ignore")\n', )) for line in open(fullpath): - line_lstrip = line.lstrip() - if (line_lstrip.startswith('from __future__ import') or - line_lstrip.startswith('matplotlib.use') or - line_lstrip.startswith('savefig') or - line_lstrip.startswith('show')): + if line.lstrip().startswith(('matplotlib.use', 'savefig', 'show')): continue tmpfile.write(line) if backend in rcsetup.interactive_bk: diff --git a/examples/text_labels_and_annotations/accented_text.py b/examples/text_labels_and_annotations/accented_text.py index ac088f4d70f9..c7f4523e600c 100644 --- a/examples/text_labels_and_annotations/accented_text.py +++ b/examples/text_labels_and_annotations/accented_text.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" ================================= Using accented text in matplotlib @@ -13,7 +12,6 @@ \^y """ -from __future__ import unicode_literals import matplotlib.pyplot as plt # Mathtext demo diff --git a/examples/text_labels_and_annotations/font_table_ttf_sgskip.py b/examples/text_labels_and_annotations/font_table_ttf_sgskip.py index 880453b55089..6de73e68dea3 100644 --- a/examples/text_labels_and_annotations/font_table_ttf_sgskip.py +++ b/examples/text_labels_and_annotations/font_table_ttf_sgskip.py @@ -19,9 +19,6 @@ from matplotlib.font_manager import FontProperties import matplotlib.pyplot as plt -import six -from six import unichr - # the font table grid labelc = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', @@ -47,7 +44,7 @@ if ccode >= 256: continue r, c = divmod(ccode, 16) - s = unichr(ccode) + s = chr(ccode) chars[r][c] = s lightgrn = (0.5, 0.8, 0.5) diff --git a/examples/text_labels_and_annotations/legend_demo.py b/examples/text_labels_and_annotations/legend_demo.py index 77db192ebe85..2b4636834147 100644 --- a/examples/text_labels_and_annotations/legend_demo.py +++ b/examples/text_labels_and_annotations/legend_demo.py @@ -10,15 +10,12 @@ First we'll show off how to make a legend for specific lines. """ -from __future__ import (absolute_import, division, - print_function, unicode_literals) import matplotlib.pyplot as plt -import numpy as np -from matplotlib.legend_handler import (HandlerLineCollection, - HandlerTuple) import matplotlib.collections as mcol +from matplotlib.legend_handler import HandlerLineCollection, HandlerTuple from matplotlib.lines import Line2D +import numpy as np t1 = np.arange(0.0, 2.0, 0.1) t2 = np.arange(0.0, 2.0, 0.01) diff --git a/examples/text_labels_and_annotations/mathtext_examples.py b/examples/text_labels_and_annotations/mathtext_examples.py index 86c349f10d11..eec403d3c531 100644 --- a/examples/text_labels_and_annotations/mathtext_examples.py +++ b/examples/text_labels_and_annotations/mathtext_examples.py @@ -5,7 +5,6 @@ Selected features of Matplotlib's math rendering engine. """ -from __future__ import print_function import matplotlib.pyplot as plt import subprocess import sys diff --git a/examples/text_labels_and_annotations/rainbow_text.py b/examples/text_labels_and_annotations/rainbow_text.py index b326be24c5f0..5dce48a46431 100644 --- a/examples/text_labels_and_annotations/rainbow_text.py +++ b/examples/text_labels_and_annotations/rainbow_text.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ ============ Rainbow text diff --git a/examples/text_labels_and_annotations/stix_fonts_demo.py b/examples/text_labels_and_annotations/stix_fonts_demo.py index 411b0ae41728..f2e5e8455b32 100644 --- a/examples/text_labels_and_annotations/stix_fonts_demo.py +++ b/examples/text_labels_and_annotations/stix_fonts_demo.py @@ -4,7 +4,6 @@ =============== """ -from __future__ import unicode_literals import subprocess import sys diff --git a/examples/text_labels_and_annotations/tex_demo.py b/examples/text_labels_and_annotations/tex_demo.py index c341a92b4b2d..01ba41b433be 100644 --- a/examples/text_labels_and_annotations/tex_demo.py +++ b/examples/text_labels_and_annotations/tex_demo.py @@ -14,7 +14,6 @@ Notice how the label for the y axis is provided using unicode! """ -from __future__ import unicode_literals import numpy as np import matplotlib matplotlib.rcParams['text.usetex'] = True diff --git a/examples/ticks_and_spines/date_index_formatter.py b/examples/ticks_and_spines/date_index_formatter.py index 5d3688583a3b..4d9e5750bb5e 100644 --- a/examples/ticks_and_spines/date_index_formatter.py +++ b/examples/ticks_and_spines/date_index_formatter.py @@ -11,7 +11,6 @@ Formatter to get the appropriate date string for a given index. """ -from __future__ import print_function import numpy as np diff --git a/examples/units/basic_units.py b/examples/units/basic_units.py index be07f0c9fce5..fa2d2103ea80 100644 --- a/examples/units/basic_units.py +++ b/examples/units/basic_units.py @@ -4,7 +4,6 @@ =========== """ -import six import math @@ -110,7 +109,7 @@ def __call__(self, *args): return TaggedValue(ret, ret_unit) -class TaggedValue(six.with_metaclass(TaggedValueMeta)): +class TaggedValue(metaclass=TaggedValueMeta): _proxies = {'__add__': ConvertAllProxy, '__sub__': ConvertAllProxy, diff --git a/examples/user_interfaces/embedding_in_tk_canvas_sgskip.py b/examples/user_interfaces/embedding_in_tk_canvas_sgskip.py index 41380b758cd6..b82483d3ab09 100644 --- a/examples/user_interfaces/embedding_in_tk_canvas_sgskip.py +++ b/examples/user_interfaces/embedding_in_tk_canvas_sgskip.py @@ -5,13 +5,11 @@ Embedding plots in a Tk Canvas. """ -import matplotlib as mpl + +import tkinter + import numpy as np -import sys -if sys.version_info[0] < 3: - import Tkinter as tk -else: - import tkinter as tk +import matplotlib as mpl import matplotlib.backends.tkagg as tkagg from matplotlib.backends.backend_agg import FigureCanvasAgg @@ -26,7 +24,7 @@ def draw_figure(canvas, figure, loc=(0, 0)): figure_canvas_agg.draw() figure_x, figure_y, figure_w, figure_h = figure.bbox.bounds figure_w, figure_h = int(figure_w), int(figure_h) - photo = tk.PhotoImage(master=canvas, width=figure_w, height=figure_h) + photo = tkinter.PhotoImage(master=canvas, width=figure_w, height=figure_h) # Position: convert from top-left anchor to center anchor canvas.create_image(loc[0] + figure_w/2, loc[1] + figure_h/2, image=photo) @@ -40,9 +38,9 @@ def draw_figure(canvas, figure, loc=(0, 0)): # Create a canvas w, h = 300, 200 -window = tk.Tk() +window = tkinter.Tk() window.title("A figure in a canvas") -canvas = tk.Canvas(window, width=w, height=h) +canvas = tkinter.Canvas(window, width=w, height=h) canvas.pack() # Generate some example data @@ -64,4 +62,4 @@ def draw_figure(canvas, figure, loc=(0, 0)): canvas.create_text(200, 50, text="Zero-crossing", anchor="s") # Let Tk take over -tk.mainloop() +tkinter.mainloop() diff --git a/examples/user_interfaces/embedding_in_tk_sgskip.py b/examples/user_interfaces/embedding_in_tk_sgskip.py index f79390d30990..ad1877a7bf90 100644 --- a/examples/user_interfaces/embedding_in_tk_sgskip.py +++ b/examples/user_interfaces/embedding_in_tk_sgskip.py @@ -5,19 +5,18 @@ """ -from six.moves import tkinter as Tk +import tkinter from matplotlib.backends.backend_tkagg import ( FigureCanvasTkAgg, NavigationToolbar2TkAgg) # Implement the default Matplotlib key bindings. from matplotlib.backend_bases import key_press_handler from matplotlib.figure import Figure -from six.moves import tkinter as Tk import numpy as np -root = Tk.Tk() +root = tkinter.Tk() root.wm_title("Embedding in Tk") fig = Figure(figsize=(5, 4), dpi=100) @@ -26,11 +25,11 @@ canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea. canvas.draw() -canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) +canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1) toolbar = NavigationToolbar2TkAgg(canvas, root) toolbar.update() -canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) +canvas._tkcanvas.pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1) def on_key_press(event): @@ -47,9 +46,9 @@ def _quit(): # Fatal Python Error: PyEval_RestoreThread: NULL tstate -button = Tk.Button(master=root, text="Quit", command=_quit) -button.pack(side=Tk.BOTTOM) +button = tkinter.Button(master=root, text="Quit", command=_quit) +button.pack(side=tkinter.BOTTOM) -Tk.mainloop() +tkinter.mainloop() # If you put root.destroy() here, it will cause an error if the window is # closed with the window manager. diff --git a/examples/user_interfaces/embedding_in_wx3_sgskip.py b/examples/user_interfaces/embedding_in_wx3_sgskip.py index f8074a488e95..8ecce24d81bc 100644 --- a/examples/user_interfaces/embedding_in_wx3_sgskip.py +++ b/examples/user_interfaces/embedding_in_wx3_sgskip.py @@ -21,7 +21,6 @@ Thanks to matplotlib and wx teams for creating such great software! """ -from __future__ import print_function import sys import time diff --git a/examples/user_interfaces/mpl_with_glade_sgskip.py b/examples/user_interfaces/mpl_with_glade_sgskip.py index ab2652b1365d..9000942fe210 100644 --- a/examples/user_interfaces/mpl_with_glade_sgskip.py +++ b/examples/user_interfaces/mpl_with_glade_sgskip.py @@ -4,7 +4,6 @@ ===================== """ -from __future__ import print_function import matplotlib matplotlib.use('GTK') diff --git a/examples/user_interfaces/pylab_with_gtk_sgskip.py b/examples/user_interfaces/pylab_with_gtk_sgskip.py index 75c623801745..b1abb3f8f73e 100644 --- a/examples/user_interfaces/pylab_with_gtk_sgskip.py +++ b/examples/user_interfaces/pylab_with_gtk_sgskip.py @@ -6,7 +6,6 @@ An example of how to use pylab to manage your figure windows, but modify the GUI by accessing the underlying gtk widgets """ -from __future__ import print_function import matplotlib matplotlib.use('GTKAgg') import matplotlib.pyplot as plt diff --git a/examples/user_interfaces/toolmanager_sgskip.py b/examples/user_interfaces/toolmanager_sgskip.py index 247997f6e2e2..7c2eeae5b845 100644 --- a/examples/user_interfaces/toolmanager_sgskip.py +++ b/examples/user_interfaces/toolmanager_sgskip.py @@ -14,7 +14,6 @@ """ -from __future__ import print_function import matplotlib # Change to the desired backend matplotlib.use('GTK3Cairo') diff --git a/examples/userdemo/pgf_fonts_sgskip.py b/examples/userdemo/pgf_fonts.py similarity index 78% rename from examples/userdemo/pgf_fonts_sgskip.py rename to examples/userdemo/pgf_fonts.py index 0528b8ef88d0..463d5c7e6887 100644 --- a/examples/userdemo/pgf_fonts_sgskip.py +++ b/examples/userdemo/pgf_fonts.py @@ -4,25 +4,21 @@ ========= """ -# -*- coding: utf-8 -*- -import matplotlib as mpl -mpl.use("pgf") -pgf_with_rc_fonts = { +import matplotlib.pyplot as plt +plt.rcParams.update({ "font.family": "serif", "font.serif": [], # use latex default serif font "font.sans-serif": ["DejaVu Sans"], # use a specific sans-serif font -} -mpl.rcParams.update(pgf_with_rc_fonts) +}) -import matplotlib.pyplot as plt plt.figure(figsize=(4.5, 2.5)) plt.plot(range(5)) plt.text(0.5, 3., "serif") plt.text(0.5, 2., "monospace", family="monospace") plt.text(2.5, 2., "sans-serif", family="sans-serif") plt.text(2.5, 1., "comic sans", family="Comic Sans MS") -plt.xlabel(u"µ is not $\\mu$") +plt.xlabel("µ is not $\\mu$") plt.tight_layout(.5) plt.savefig("pgf_fonts.pdf") diff --git a/examples/userdemo/pgf_preamble_sgskip.py b/examples/userdemo/pgf_preamble_sgskip.py index 46dd45bb1d40..eccdefa0d6e1 100644 --- a/examples/userdemo/pgf_preamble_sgskip.py +++ b/examples/userdemo/pgf_preamble_sgskip.py @@ -4,15 +4,11 @@ ============ """ -# -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, print_function, - unicode_literals) - -import six import matplotlib as mpl mpl.use("pgf") -pgf_with_custom_preamble = { +import matplotlib.pyplot as plt +plt.rcParams.update({ "font.family": "serif", # use serif/main font for text elements "text.usetex": True, # use inline math for ticks "pgf.rcfonts": False, # don't setup fonts from rc parameters @@ -23,10 +19,8 @@ r"\setmathfont{xits-math.otf}", r"\setmainfont{DejaVu Serif}", # serif font via preamble ] -} -mpl.rcParams.update(pgf_with_custom_preamble) +}) -import matplotlib.pyplot as plt plt.figure(figsize=(4.5, 2.5)) plt.plot(range(5)) plt.xlabel("unicode text: я, ψ, €, ü, \\unitfrac[10]{°}{µm}") diff --git a/examples/userdemo/pgf_texsystem_sgskip.py b/examples/userdemo/pgf_texsystem.py similarity index 77% rename from examples/userdemo/pgf_texsystem_sgskip.py rename to examples/userdemo/pgf_texsystem.py index c4914d1736cf..d3e535183539 100644 --- a/examples/userdemo/pgf_texsystem_sgskip.py +++ b/examples/userdemo/pgf_texsystem.py @@ -4,27 +4,23 @@ ============= """ -# -*- coding: utf-8 -*- -import matplotlib as mpl -mpl.use("pgf") -pgf_with_pdflatex = { +import matplotlib.pyplot as plt +plt.rcParams.update({ "pgf.texsystem": "pdflatex", "pgf.preamble": [ r"\usepackage[utf8x]{inputenc}", r"\usepackage[T1]{fontenc}", r"\usepackage{cmbright}", ] -} -mpl.rcParams.update(pgf_with_pdflatex) +}) -import matplotlib.pyplot as plt plt.figure(figsize=(4.5, 2.5)) plt.plot(range(5)) plt.text(0.5, 3., "serif", family="serif") plt.text(0.5, 2., "monospace", family="monospace") plt.text(2.5, 2., "sans-serif", family="sans-serif") -plt.xlabel(u"µ is not $\\mu$") +plt.xlabel(r"µ is not $\mu$") plt.tight_layout(.5) plt.savefig("pgf_texsystem.pdf") diff --git a/examples/widgets/lasso_selector_demo_sgskip.py b/examples/widgets/lasso_selector_demo_sgskip.py index 9bace4319c51..ac6c7325199f 100644 --- a/examples/widgets/lasso_selector_demo_sgskip.py +++ b/examples/widgets/lasso_selector_demo_sgskip.py @@ -10,7 +10,6 @@ on the graph, hold, and drag it around the points you need to select. """ -from __future__ import print_function import numpy as np diff --git a/examples/widgets/menu.py b/examples/widgets/menu.py index 6458041222ae..a099b1fc92ff 100644 --- a/examples/widgets/menu.py +++ b/examples/widgets/menu.py @@ -4,7 +4,6 @@ ==== """ -from __future__ import division, print_function import numpy as np import matplotlib import matplotlib.colors as colors diff --git a/examples/widgets/rectangle_selector.py b/examples/widgets/rectangle_selector.py index 56eb208639ce..cbdaf8026197 100644 --- a/examples/widgets/rectangle_selector.py +++ b/examples/widgets/rectangle_selector.py @@ -10,7 +10,6 @@ method 'self.ignore()' it is checked whether the button from eventpress and eventrelease are the same. """ -from __future__ import print_function from matplotlib.widgets import RectangleSelector import numpy as np import matplotlib.pyplot as plt diff --git a/tutorials/text/pgf.py b/tutorials/text/pgf.py index 27415528e160..162f74807135 100644 --- a/tutorials/text/pgf.py +++ b/tutorials/text/pgf.py @@ -71,7 +71,7 @@ When saving to ``.pgf``, the font configuration matplotlib used for the layout of the figure is included in the header of the text file. -.. literalinclude:: ../../gallery/userdemo/pgf_fonts_sgskip.py +.. literalinclude:: ../../gallery/userdemo/pgf_fonts.py :end-before: plt.savefig @@ -107,7 +107,7 @@ ``'pdflatex'``. Please note that when selecting pdflatex the fonts and unicode handling must be configured in the preamble. -.. literalinclude:: ../../gallery/userdemo/pgf_texsystem_sgskip.py +.. literalinclude:: ../../gallery/userdemo/pgf_texsystem.py :end-before: plt.savefig