diff --git a/examples/lines_bars_and_markers/filled_step.py b/examples/lines_bars_and_markers/filled_step.py index 6f37377cb331..253211be1cb6 100644 --- a/examples/lines_bars_and_markers/filled_step.py +++ b/examples/lines_bars_and_markers/filled_step.py @@ -7,7 +7,6 @@ """ import itertools -from collections import OrderedDict from functools import partial import numpy as np @@ -188,7 +187,7 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None, np.random.seed(19680801) stack_data = np.random.randn(4, 12250) -dict_data = OrderedDict(zip((c['label'] for c in label_cycle), stack_data)) +dict_data = dict(zip((c['label'] for c in label_cycle), stack_data)) ############################################################################### # Work with plain arrays diff --git a/lib/matplotlib/_color_data.py b/lib/matplotlib/_color_data.py index e50998b18fd5..dc3d18f976da 100644 --- a/lib/matplotlib/_color_data.py +++ b/lib/matplotlib/_color_data.py @@ -1,6 +1,3 @@ -from collections import OrderedDict - - BASE_COLORS = { 'b': (0, 0, 1), # blue 'g': (0, 0.5, 0), # green @@ -14,22 +11,19 @@ # These colors are from Tableau -TABLEAU_COLORS = ( - ('blue', '#1f77b4'), - ('orange', '#ff7f0e'), - ('green', '#2ca02c'), - ('red', '#d62728'), - ('purple', '#9467bd'), - ('brown', '#8c564b'), - ('pink', '#e377c2'), - ('gray', '#7f7f7f'), - ('olive', '#bcbd22'), - ('cyan', '#17becf'), -) +TABLEAU_COLORS = { + 'tab:blue': '#1f77b4', + 'tab:orange': '#ff7f0e', + 'tab:green': '#2ca02c', + 'tab:red': '#d62728', + 'tab:purple': '#9467bd', + 'tab:brown': '#8c564b', + 'tab:pink': '#e377c2', + 'tab:gray': '#7f7f7f', + 'tab:olive': '#bcbd22', + 'tab:cyan': '#17becf', +} -# Normalize name to "tab:" to avoid name collisions. -TABLEAU_COLORS = OrderedDict( - ('tab:' + name, value) for name, value in TABLEAU_COLORS) # This mapping of color names -> hex values is taken from # a survey run by Randall Munroe see: diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 406e9db5ae54..e95cda7aa259 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -1,4 +1,4 @@ -from collections import OrderedDict, namedtuple +from collections import namedtuple from functools import wraps import inspect import logging @@ -1683,8 +1683,7 @@ def setp(obj, *args, file=None, **kwargs): if len(args) % 2: raise ValueError('The set args must be string, value pairs') - # put args into ordereddict to maintain order - funcvals = OrderedDict((k, v) for k, v in zip(args[::2], args[1::2])) + funcvals = dict(zip(args[::2], args[1::2])) ret = [o.update(funcvals) for o in objs] + [o.set(**kwargs) for o in objs] return list(cbook.flatten(ret)) diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 530df4b12dd2..343b8a35ec63 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -5,7 +5,6 @@ """ import codecs -import collections from datetime import datetime from enum import Enum from functools import total_ordering @@ -682,15 +681,14 @@ def __init__(self, filename, metadata=None): self._soft_mask_states = {} self._soft_mask_seq = (Name(f'SM{i}') for i in itertools.count(1)) self._soft_mask_groups = [] - # reproducible writeHatches needs an ordered dict: - self.hatchPatterns = collections.OrderedDict() + self.hatchPatterns = {} self._hatch_pattern_seq = (Name(f'H{i}') for i in itertools.count(1)) self.gouraudTriangles = [] - self._images = collections.OrderedDict() # reproducible writeImages + self._images = {} self._image_seq = (Name(f'I{i}') for i in itertools.count(1)) - self.markers = collections.OrderedDict() # reproducible writeMarkers + self.markers = {} self.multi_byte_charprocs = {} self.paths = [] diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index 51c0c17b8089..a1a11061b978 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -1,4 +1,3 @@ -from collections import OrderedDict import base64 import datetime import gzip @@ -287,10 +286,10 @@ def __init__(self, width, height, svgwriter, basename=None, image_dpi=72, self._groupd = {} self.basename = basename self._image_counter = itertools.count() - self._clipd = OrderedDict() + self._clipd = {} self._markers = {} self._path_collection_id = 0 - self._hatchd = OrderedDict() + self._hatchd = {} self._has_gouraud = False self._n_gradients = 0 @@ -1174,7 +1173,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None): writer.start('text') # Sort the characters by font, and output one tspan for each. - spans = OrderedDict() + spans = {} for font, fontsize, thetext, new_x, new_y in glyphs: style = generate_css({ 'font-size': short_float_fmt(fontsize) + 'px', diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 3d5d5c2311a0..df3f6d7a0413 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -1,4 +1,3 @@ -from collections import OrderedDict import copy import os from pathlib import Path @@ -460,8 +459,7 @@ def test_rcparams_reset_after_fail(): with mpl.rc_context(rc={'text.usetex': False}): assert mpl.rcParams['text.usetex'] is False with pytest.raises(KeyError): - with mpl.rc_context(rc=OrderedDict([('text.usetex', True), - ('test.blah', True)])): + with mpl.rc_context(rc={'text.usetex': True, 'test.blah': True}): pass assert mpl.rcParams['text.usetex'] is False diff --git a/lib/matplotlib/tests/test_style.py b/lib/matplotlib/tests/test_style.py index 538c89e838c5..aea09462b197 100644 --- a/lib/matplotlib/tests/test_style.py +++ b/lib/matplotlib/tests/test_style.py @@ -1,4 +1,3 @@ -from collections import OrderedDict from contextlib import contextmanager import gc from pathlib import Path @@ -138,10 +137,9 @@ def test_context_with_union_of_dict_and_namedstyle(): def test_context_with_badparam(): original_value = 'gray' other_value = 'blue' - d = OrderedDict([(PARAM, original_value), ('badparam', None)]) with style.context({PARAM: other_value}): assert mpl.rcParams[PARAM] == other_value - x = style.context([d]) + x = style.context({PARAM: original_value, 'badparam': None}) with pytest.raises(KeyError): with x: pass diff --git a/tutorials/colors/colormaps.py b/tutorials/colors/colormaps.py index f8764a6a7367..12bbbb50a319 100644 --- a/tutorials/colors/colormaps.py +++ b/tutorials/colors/colormaps.py @@ -78,9 +78,9 @@ import matplotlib.pyplot as plt from matplotlib import cm from colorspacious import cspace_converter -from collections import OrderedDict -cmaps = OrderedDict() + +cmaps = {} ############################################################################### # Sequential