From 48a17983d3545e73961ca99475dec71b463408c0 Mon Sep 17 00:00:00 2001 From: Salinder Sidhu Date: Wed, 7 Mar 2018 01:18:32 -0500 Subject: [PATCH 1/9] Added markevery validator to rcparams with basic rcparams test --- lib/matplotlib/rcsetup.py | 30 +++++++++++++++++++++++++++ lib/matplotlib/tests/test_rcparams.py | 12 +++++++++++ 2 files changed, 42 insertions(+) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index a4c86779ba4e..be5813db8682 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -534,7 +534,36 @@ def validate_ps_distiller(s): _validate_negative_linestyle = ValidateInStrings('negative_linestyle', ['solid', 'dashed'], ignorecase=True) +def validate_markevery(s): + """ + Validate the markevery property of a Line2D object. + + Parameters + ---------- + s : None, int, float, slice, length-2 tuple of ints, + length-2 tuple of floats, list + + Returns + ------- + s : None, int, float, slice, length-2 tuple of ints, + length-2 tuple of floats, list, ValueError + + """ + + if isinstance(s, tuple): + # Ensure correct length of 2 + if len(s) != 2: + raise ValueError("'markevery' tuple must be a length of 2") + # Ensure that all elements in the tuple are of type int + if not all(isinstance(x, int) for x in s): + raise ValueError("'markevery' tuple ") + # Ensure that all elements in the tuple are of type float + elif not all(isinstance(x, float) for x in s): + raise ValueError("'markevery' tuple ") + + return s; +validate_markeverylist = _listify_validator(validate_markevery) validate_legend_loc = ValidateInStrings( 'legend_loc', @@ -676,6 +705,7 @@ def validate_hatch(s): 'markersize': validate_floatlist, 'markeredgewidth': validate_floatlist, 'markeredgecolor': validate_colorlist, + 'markevery': validate_markeverylist, 'alpha': validate_floatlist, 'marker': validate_stringlist, 'hatch': validate_hatchlist, diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index a4fd6fd0e96a..242bda76a5ac 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -23,6 +23,7 @@ validate_cycler, validate_hatch, validate_hist_bins, + validate_markevery, _validate_linestyle) @@ -326,6 +327,17 @@ def generate_validator_testcases(valid): ), 'fail': (('aardvark', ValueError), ) + }, + {'validator': validate_markevery, + 'success': ((None,None), + (1,1), + (0.1,0.1) + ), + 'fail': (((1,2,3), ValueError), + ((0.1,0.2,0.3), ValueError), + ((1,0.1), ValueError), + (('abc'), ValueError) + ) } ) From e21dd0faf38a7acd61e214eb8b758fc74ed16f1f Mon Sep 17 00:00:00 2001 From: Salinder Sidhu Date: Wed, 7 Mar 2018 01:18:32 -0500 Subject: [PATCH 2/9] Added markevery validator to rcparams with basic rcparams test --- lib/matplotlib/rcsetup.py | 30 +++++++++++++++++++++++++++ lib/matplotlib/tests/test_rcparams.py | 12 +++++++++++ 2 files changed, 42 insertions(+) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index a4c86779ba4e..be5813db8682 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -534,7 +534,36 @@ def validate_ps_distiller(s): _validate_negative_linestyle = ValidateInStrings('negative_linestyle', ['solid', 'dashed'], ignorecase=True) +def validate_markevery(s): + """ + Validate the markevery property of a Line2D object. + + Parameters + ---------- + s : None, int, float, slice, length-2 tuple of ints, + length-2 tuple of floats, list + + Returns + ------- + s : None, int, float, slice, length-2 tuple of ints, + length-2 tuple of floats, list, ValueError + + """ + + if isinstance(s, tuple): + # Ensure correct length of 2 + if len(s) != 2: + raise ValueError("'markevery' tuple must be a length of 2") + # Ensure that all elements in the tuple are of type int + if not all(isinstance(x, int) for x in s): + raise ValueError("'markevery' tuple ") + # Ensure that all elements in the tuple are of type float + elif not all(isinstance(x, float) for x in s): + raise ValueError("'markevery' tuple ") + + return s; +validate_markeverylist = _listify_validator(validate_markevery) validate_legend_loc = ValidateInStrings( 'legend_loc', @@ -676,6 +705,7 @@ def validate_hatch(s): 'markersize': validate_floatlist, 'markeredgewidth': validate_floatlist, 'markeredgecolor': validate_colorlist, + 'markevery': validate_markeverylist, 'alpha': validate_floatlist, 'marker': validate_stringlist, 'hatch': validate_hatchlist, diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index a4fd6fd0e96a..242bda76a5ac 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -23,6 +23,7 @@ validate_cycler, validate_hatch, validate_hist_bins, + validate_markevery, _validate_linestyle) @@ -326,6 +327,17 @@ def generate_validator_testcases(valid): ), 'fail': (('aardvark', ValueError), ) + }, + {'validator': validate_markevery, + 'success': ((None,None), + (1,1), + (0.1,0.1) + ), + 'fail': (((1,2,3), ValueError), + ((0.1,0.2,0.3), ValueError), + ((1,0.1), ValueError), + (('abc'), ValueError) + ) } ) From 8afad9158310f4500e8478d7fcfea362e594fc2a Mon Sep 17 00:00:00 2001 From: Salinder Sidhu Date: Wed, 7 Mar 2018 21:32:07 -0500 Subject: [PATCH 3/9] Finished markevery validator and test cases. Added what's new and example code for markevery --- .../next_whats_new/markevery_prop_cycle.rst | 7 ++ .../markevery_prop_cycle.py | 69 +++++++++++++++++++ lib/matplotlib/rcsetup.py | 44 ++++++++---- lib/matplotlib/tests/test_rcparams.py | 19 +++-- 4 files changed, 121 insertions(+), 18 deletions(-) create mode 100644 doc/users/next_whats_new/markevery_prop_cycle.rst create mode 100644 examples/lines_bars_and_markers/markevery_prop_cycle.py diff --git a/doc/users/next_whats_new/markevery_prop_cycle.rst b/doc/users/next_whats_new/markevery_prop_cycle.rst new file mode 100644 index 000000000000..05e647cbfa80 --- /dev/null +++ b/doc/users/next_whats_new/markevery_prop_cycle.rst @@ -0,0 +1,7 @@ +Implemented support for axes.prop_cycle property markevery in rcParams +---------------------------------------------------------------------- + +The Matplotlib ``rcParams`` settings object now supports configuration +of the attribute `axes.prop_cycle` with cyclers using the `markevery` +Line2D object property. An example of this feature is provided at +`~matplotlib/examples/lines_bars_and_markers/markevery_prop_cycle.py` \ No newline at end of file diff --git a/examples/lines_bars_and_markers/markevery_prop_cycle.py b/examples/lines_bars_and_markers/markevery_prop_cycle.py new file mode 100644 index 000000000000..76a8843fa784 --- /dev/null +++ b/examples/lines_bars_and_markers/markevery_prop_cycle.py @@ -0,0 +1,69 @@ +""" +================================================================= +Implemented support for prop_cycle property markevery in rcParams +================================================================= + +This example demonstrates a working solution to issue #8576, providing full +support of the markevery property for axes.prop_cycle assignments through +rcParams. Makes use of the same list of markevery cases from +https://matplotlib.org/examples/pylab_examples/markevery_demo.html + +Renders a plot with shifted-sine curves along each column with +a unique markevery value for each sine curve. +""" +from __future__ import division +from cycler import cycler +import numpy as np +import matplotlib as mpl +import matplotlib.pyplot as plt +import matplotlib.patches as mpatches + +# Define a list of markevery cases and color cases to plot +cases = [None, + 8, + (30, 8), + [16, 24, 30], + [0, -1], + slice(100, 200, 3), + 0.1, + 0.3, + 1.5, + (0.0, 0.1), + (0.45, 0.1)] + +colors = ['#1f77b4', + '#ff7f0e', + '#2ca02c', + '#d62728', + '#9467bd', + '#8c564b', + '#e377c2', + '#7f7f7f', + '#bcbd22', + '#17becf', + '#1a55FF'] + +# Create two different cyclers to use with axes.prop_cycle +markevery_cycler = cycler(markevery=cases) +color_cycler = cycler('color', colors) + +# Configure rcParams axes.prop_cycle with custom cycler +custom_cycler = color_cycler + markevery_cycler +mpl.rcParams['axes.prop_cycle'] = custom_cycler + +# Create data points and offsets +x = np.linspace(0, 2 * np.pi) +offsets = np.linspace(0, 2 * np.pi, 11, endpoint=False) +yy = np.transpose([np.sin(x + phi) for phi in offsets]) + +# Set the plot curve with markers and a title +fig = plt.figure() +ax = fig.add_axes([0.1, 0.1, 0.6, 0.75]) + +for i in range(len(cases)): + ax.plot(yy[:, i], marker='o', label=str(cases[i])) + ax.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) + +plt.title('Support for axes.prop_cycle cycler with markevery') + +plt.show() diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index be5813db8682..06e6d90845cc 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -541,27 +541,43 @@ def validate_markevery(s): Parameters ---------- s : None, int, float, slice, length-2 tuple of ints, - length-2 tuple of floats, list + length-2 tuple of floats, list of ints Returns ------- s : None, int, float, slice, length-2 tuple of ints, - length-2 tuple of floats, list, ValueError + length-2 tuple of floats, list of ints """ + # Validate s against type slice + if isinstance(s, slice): + return s + # Validate s against type tuple and list + if isinstance(s, Iterable): + if isinstance(s, tuple): + tupMaxLength = 2 + tupType = type(s[0]) + if len(s) != tupMaxLength: + raise ValueError("'markevery' tuple must have a length " + "of %d" % (tupMaxLength)) + if tupType is int and not all(isinstance(e, int) for e in s): + raise ValueError("'markevery' tuple with first element of " + "type int must have all elements of type " + "int") + if tupType is float and not all(isinstance(e, float) for e in s): + raise ValueError("'markevery' tuple with first element of " + "type float must have all elements of type " + "float") + if isinstance(s, list): + if not all(isinstance(e, int) for e in s): + raise ValueError("'markevery' list must have all elements " + "of type int") + # Validate s against type float int and None + elif not isinstance(s, (float, int)): + if s is not None: + raise TypeError("'markevery' is of an invalid type") - if isinstance(s, tuple): - # Ensure correct length of 2 - if len(s) != 2: - raise ValueError("'markevery' tuple must be a length of 2") - # Ensure that all elements in the tuple are of type int - if not all(isinstance(x, int) for x in s): - raise ValueError("'markevery' tuple ") - # Ensure that all elements in the tuple are of type float - elif not all(isinstance(x, float) for x in s): - raise ValueError("'markevery' tuple ") - - return s; + return s validate_markeverylist = _listify_validator(validate_markevery) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 242bda76a5ac..68bba4d030a9 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -329,14 +329,25 @@ def generate_validator_testcases(valid): ) }, {'validator': validate_markevery, - 'success': ((None,None), - (1,1), - (0.1,0.1) + 'success': ((None, None), + (1, 1), + (0.1, 0.1), + ((1,1), (1,1)), + ((0.1,0.1), (0.1,0.1)), + ([1,2,3], [1,2,3]), + (slice(2), slice(None,2,None)), + (slice(1,2,3), slice(1,2,3)) ), 'fail': (((1,2,3), ValueError), ((0.1,0.2,0.3), ValueError), + ((0.1,2,3), ValueError), + ((1,0.2,0.3), ValueError), ((1,0.1), ValueError), - (('abc'), ValueError) + ((0.1,1), ValueError), + (('abc'), ValueError), + (('a'), ValueError), + ('abc', ValueError), + ('a', ValueError) ) } ) From 3bee9363d002f9d9bdca93746d5048219e7e4f1d Mon Sep 17 00:00:00 2001 From: Salinder Sidhu Date: Wed, 7 Mar 2018 01:18:32 -0500 Subject: [PATCH 4/9] Added markevery validator to rcparams with basic rcparams test --- lib/matplotlib/rcsetup.py | 30 +++++++++++++++++++++++++++ lib/matplotlib/tests/test_rcparams.py | 12 +++++++++++ 2 files changed, 42 insertions(+) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index a4c86779ba4e..be5813db8682 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -534,7 +534,36 @@ def validate_ps_distiller(s): _validate_negative_linestyle = ValidateInStrings('negative_linestyle', ['solid', 'dashed'], ignorecase=True) +def validate_markevery(s): + """ + Validate the markevery property of a Line2D object. + + Parameters + ---------- + s : None, int, float, slice, length-2 tuple of ints, + length-2 tuple of floats, list + + Returns + ------- + s : None, int, float, slice, length-2 tuple of ints, + length-2 tuple of floats, list, ValueError + + """ + + if isinstance(s, tuple): + # Ensure correct length of 2 + if len(s) != 2: + raise ValueError("'markevery' tuple must be a length of 2") + # Ensure that all elements in the tuple are of type int + if not all(isinstance(x, int) for x in s): + raise ValueError("'markevery' tuple ") + # Ensure that all elements in the tuple are of type float + elif not all(isinstance(x, float) for x in s): + raise ValueError("'markevery' tuple ") + + return s; +validate_markeverylist = _listify_validator(validate_markevery) validate_legend_loc = ValidateInStrings( 'legend_loc', @@ -676,6 +705,7 @@ def validate_hatch(s): 'markersize': validate_floatlist, 'markeredgewidth': validate_floatlist, 'markeredgecolor': validate_colorlist, + 'markevery': validate_markeverylist, 'alpha': validate_floatlist, 'marker': validate_stringlist, 'hatch': validate_hatchlist, diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index a4fd6fd0e96a..242bda76a5ac 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -23,6 +23,7 @@ validate_cycler, validate_hatch, validate_hist_bins, + validate_markevery, _validate_linestyle) @@ -326,6 +327,17 @@ def generate_validator_testcases(valid): ), 'fail': (('aardvark', ValueError), ) + }, + {'validator': validate_markevery, + 'success': ((None,None), + (1,1), + (0.1,0.1) + ), + 'fail': (((1,2,3), ValueError), + ((0.1,0.2,0.3), ValueError), + ((1,0.1), ValueError), + (('abc'), ValueError) + ) } ) From b73fe0f49943ad79c807a389a4d42bcd95a12386 Mon Sep 17 00:00:00 2001 From: Salinder Sidhu Date: Wed, 7 Mar 2018 21:32:07 -0500 Subject: [PATCH 5/9] Finished markevery validator and test cases. Added what's new and example code for markevery --- .../next_whats_new/markevery_prop_cycle.rst | 7 ++ .../markevery_prop_cycle.py | 69 +++++++++++++++++++ lib/matplotlib/rcsetup.py | 44 ++++++++---- lib/matplotlib/tests/test_rcparams.py | 19 +++-- 4 files changed, 121 insertions(+), 18 deletions(-) create mode 100644 doc/users/next_whats_new/markevery_prop_cycle.rst create mode 100644 examples/lines_bars_and_markers/markevery_prop_cycle.py diff --git a/doc/users/next_whats_new/markevery_prop_cycle.rst b/doc/users/next_whats_new/markevery_prop_cycle.rst new file mode 100644 index 000000000000..05e647cbfa80 --- /dev/null +++ b/doc/users/next_whats_new/markevery_prop_cycle.rst @@ -0,0 +1,7 @@ +Implemented support for axes.prop_cycle property markevery in rcParams +---------------------------------------------------------------------- + +The Matplotlib ``rcParams`` settings object now supports configuration +of the attribute `axes.prop_cycle` with cyclers using the `markevery` +Line2D object property. An example of this feature is provided at +`~matplotlib/examples/lines_bars_and_markers/markevery_prop_cycle.py` \ No newline at end of file diff --git a/examples/lines_bars_and_markers/markevery_prop_cycle.py b/examples/lines_bars_and_markers/markevery_prop_cycle.py new file mode 100644 index 000000000000..76a8843fa784 --- /dev/null +++ b/examples/lines_bars_and_markers/markevery_prop_cycle.py @@ -0,0 +1,69 @@ +""" +================================================================= +Implemented support for prop_cycle property markevery in rcParams +================================================================= + +This example demonstrates a working solution to issue #8576, providing full +support of the markevery property for axes.prop_cycle assignments through +rcParams. Makes use of the same list of markevery cases from +https://matplotlib.org/examples/pylab_examples/markevery_demo.html + +Renders a plot with shifted-sine curves along each column with +a unique markevery value for each sine curve. +""" +from __future__ import division +from cycler import cycler +import numpy as np +import matplotlib as mpl +import matplotlib.pyplot as plt +import matplotlib.patches as mpatches + +# Define a list of markevery cases and color cases to plot +cases = [None, + 8, + (30, 8), + [16, 24, 30], + [0, -1], + slice(100, 200, 3), + 0.1, + 0.3, + 1.5, + (0.0, 0.1), + (0.45, 0.1)] + +colors = ['#1f77b4', + '#ff7f0e', + '#2ca02c', + '#d62728', + '#9467bd', + '#8c564b', + '#e377c2', + '#7f7f7f', + '#bcbd22', + '#17becf', + '#1a55FF'] + +# Create two different cyclers to use with axes.prop_cycle +markevery_cycler = cycler(markevery=cases) +color_cycler = cycler('color', colors) + +# Configure rcParams axes.prop_cycle with custom cycler +custom_cycler = color_cycler + markevery_cycler +mpl.rcParams['axes.prop_cycle'] = custom_cycler + +# Create data points and offsets +x = np.linspace(0, 2 * np.pi) +offsets = np.linspace(0, 2 * np.pi, 11, endpoint=False) +yy = np.transpose([np.sin(x + phi) for phi in offsets]) + +# Set the plot curve with markers and a title +fig = plt.figure() +ax = fig.add_axes([0.1, 0.1, 0.6, 0.75]) + +for i in range(len(cases)): + ax.plot(yy[:, i], marker='o', label=str(cases[i])) + ax.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) + +plt.title('Support for axes.prop_cycle cycler with markevery') + +plt.show() diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index be5813db8682..06e6d90845cc 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -541,27 +541,43 @@ def validate_markevery(s): Parameters ---------- s : None, int, float, slice, length-2 tuple of ints, - length-2 tuple of floats, list + length-2 tuple of floats, list of ints Returns ------- s : None, int, float, slice, length-2 tuple of ints, - length-2 tuple of floats, list, ValueError + length-2 tuple of floats, list of ints """ + # Validate s against type slice + if isinstance(s, slice): + return s + # Validate s against type tuple and list + if isinstance(s, Iterable): + if isinstance(s, tuple): + tupMaxLength = 2 + tupType = type(s[0]) + if len(s) != tupMaxLength: + raise ValueError("'markevery' tuple must have a length " + "of %d" % (tupMaxLength)) + if tupType is int and not all(isinstance(e, int) for e in s): + raise ValueError("'markevery' tuple with first element of " + "type int must have all elements of type " + "int") + if tupType is float and not all(isinstance(e, float) for e in s): + raise ValueError("'markevery' tuple with first element of " + "type float must have all elements of type " + "float") + if isinstance(s, list): + if not all(isinstance(e, int) for e in s): + raise ValueError("'markevery' list must have all elements " + "of type int") + # Validate s against type float int and None + elif not isinstance(s, (float, int)): + if s is not None: + raise TypeError("'markevery' is of an invalid type") - if isinstance(s, tuple): - # Ensure correct length of 2 - if len(s) != 2: - raise ValueError("'markevery' tuple must be a length of 2") - # Ensure that all elements in the tuple are of type int - if not all(isinstance(x, int) for x in s): - raise ValueError("'markevery' tuple ") - # Ensure that all elements in the tuple are of type float - elif not all(isinstance(x, float) for x in s): - raise ValueError("'markevery' tuple ") - - return s; + return s validate_markeverylist = _listify_validator(validate_markevery) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 242bda76a5ac..68bba4d030a9 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -329,14 +329,25 @@ def generate_validator_testcases(valid): ) }, {'validator': validate_markevery, - 'success': ((None,None), - (1,1), - (0.1,0.1) + 'success': ((None, None), + (1, 1), + (0.1, 0.1), + ((1,1), (1,1)), + ((0.1,0.1), (0.1,0.1)), + ([1,2,3], [1,2,3]), + (slice(2), slice(None,2,None)), + (slice(1,2,3), slice(1,2,3)) ), 'fail': (((1,2,3), ValueError), ((0.1,0.2,0.3), ValueError), + ((0.1,2,3), ValueError), + ((1,0.2,0.3), ValueError), ((1,0.1), ValueError), - (('abc'), ValueError) + ((0.1,1), ValueError), + (('abc'), ValueError), + (('a'), ValueError), + ('abc', ValueError), + ('a', ValueError) ) } ) From c4d4f11e2152ecc5147ba159533b458f13164f94 Mon Sep 17 00:00:00 2001 From: Salinder Sidhu Date: Thu, 8 Mar 2018 14:29:35 -0500 Subject: [PATCH 6/9] Increased test coverage of markevery validator --- lib/matplotlib/rcsetup.py | 2 ++ lib/matplotlib/tests/test_rcparams.py | 34 ++++++++++++++++----------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 06e6d90845cc..2d2ca8ad46c0 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -568,6 +568,8 @@ def validate_markevery(s): raise ValueError("'markevery' tuple with first element of " "type float must have all elements of type " "float") + if not instance(tupType, (float, int)): + raise TypeError("'markevery' tuple is of an invalid type") if isinstance(s, list): if not all(isinstance(e, int) for e in s): raise ValueError("'markevery' list must have all elements " diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 68bba4d030a9..c85c354d2b6a 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -332,22 +332,28 @@ def generate_validator_testcases(valid): 'success': ((None, None), (1, 1), (0.1, 0.1), - ((1,1), (1,1)), - ((0.1,0.1), (0.1,0.1)), - ([1,2,3], [1,2,3]), - (slice(2), slice(None,2,None)), - (slice(1,2,3), slice(1,2,3)) + ((1, 1), (1, 1)), + ((0.1, 0.1), (0.1, 0.1)), + ([1, 2, 3], [1, 2, 3]), + (slice(2), slice(None, 2, None)), + (slice(1, 2, 3), slice(1, 2, 3)) ), - 'fail': (((1,2,3), ValueError), - ((0.1,0.2,0.3), ValueError), - ((0.1,2,3), ValueError), - ((1,0.2,0.3), ValueError), - ((1,0.1), ValueError), - ((0.1,1), ValueError), + 'fail': (((1, 2, 3), ValueError), + ([1, 2, 0.3], ValueError), + (['a', 2, 3], ValueError), + ([1, 2, 'a'], ValueError), + ((0.1, 0.2, 0.3), ValueError), + ((0.1, 2, 3), ValueError), + ((1, 0.2, 0.3), ValueError), + ((1, 0.1), ValueError), + ((0.1, 1), ValueError), (('abc'), ValueError), - (('a'), ValueError), - ('abc', ValueError), - ('a', ValueError) + ((1, 'a'), ValueError), + ((0.1, 'b'), ValueError), + (('a', 1), ValueError), + (('a', 0.1), ValueError), + ('abc', TypeError), + ('a', TypeError) ) } ) From 9a2def6be444e460154ec1f25950629dbb769b03 Mon Sep 17 00:00:00 2001 From: Salinder Sidhu Date: Thu, 8 Mar 2018 14:37:56 -0500 Subject: [PATCH 7/9] Fixed typo --- lib/matplotlib/rcsetup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 2d2ca8ad46c0..a21c7e0bcf76 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -568,7 +568,7 @@ def validate_markevery(s): raise ValueError("'markevery' tuple with first element of " "type float must have all elements of type " "float") - if not instance(tupType, (float, int)): + if not isinstance(tupType, (float, int)): raise TypeError("'markevery' tuple is of an invalid type") if isinstance(s, list): if not all(isinstance(e, int) for e in s): From 3a7105586770532f21dec5a443012145a4d3eec3 Mon Sep 17 00:00:00 2001 From: Salinder Sidhu Date: Thu, 8 Mar 2018 14:54:16 -0500 Subject: [PATCH 8/9] Fixed validate_markevery --- lib/matplotlib/rcsetup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index a21c7e0bcf76..65f65253b9c9 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -568,7 +568,7 @@ def validate_markevery(s): raise ValueError("'markevery' tuple with first element of " "type float must have all elements of type " "float") - if not isinstance(tupType, (float, int)): + if tupType is not float and tupType is not int: raise TypeError("'markevery' tuple is of an invalid type") if isinstance(s, list): if not all(isinstance(e, int) for e in s): From 3154b9019b49f3f9c3f3186dc3a1e8ee8cd286a4 Mon Sep 17 00:00:00 2001 From: Salinder Sidhu Date: Thu, 8 Mar 2018 16:47:06 -0500 Subject: [PATCH 9/9] Resolved build errors --- .../markevery_prop_cycle.py | 2 - lib/matplotlib/rcsetup.py | 44 +++++++++---------- lib/matplotlib/tests/test_rcparams.py | 31 ++++++------- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/examples/lines_bars_and_markers/markevery_prop_cycle.py b/examples/lines_bars_and_markers/markevery_prop_cycle.py index 76a8843fa784..e680ab2a0d98 100644 --- a/examples/lines_bars_and_markers/markevery_prop_cycle.py +++ b/examples/lines_bars_and_markers/markevery_prop_cycle.py @@ -11,12 +11,10 @@ Renders a plot with shifted-sine curves along each column with a unique markevery value for each sine curve. """ -from __future__ import division from cycler import cycler import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt -import matplotlib.patches as mpatches # Define a list of markevery cases and color cases to plot cases = [None, diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 65f65253b9c9..99e445863877 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -552,28 +552,28 @@ def validate_markevery(s): # Validate s against type slice if isinstance(s, slice): return s - # Validate s against type tuple and list - if isinstance(s, Iterable): - if isinstance(s, tuple): - tupMaxLength = 2 - tupType = type(s[0]) - if len(s) != tupMaxLength: - raise ValueError("'markevery' tuple must have a length " - "of %d" % (tupMaxLength)) - if tupType is int and not all(isinstance(e, int) for e in s): - raise ValueError("'markevery' tuple with first element of " - "type int must have all elements of type " - "int") - if tupType is float and not all(isinstance(e, float) for e in s): - raise ValueError("'markevery' tuple with first element of " - "type float must have all elements of type " - "float") - if tupType is not float and tupType is not int: - raise TypeError("'markevery' tuple is of an invalid type") - if isinstance(s, list): - if not all(isinstance(e, int) for e in s): - raise ValueError("'markevery' list must have all elements " - "of type int") + # Validate s against type tuple + if isinstance(s, tuple): + tupMaxLength = 2 + tupType = type(s[0]) + if len(s) != tupMaxLength: + raise TypeError("'markevery' tuple must have a length of " + "%d" % (tupMaxLength)) + if tupType is int and not all(isinstance(e, int) for e in s): + raise TypeError("'markevery' tuple with first element of " + "type int must have all elements of type " + "int") + if tupType is float and not all(isinstance(e, float) for e in s): + raise TypeError("'markevery' tuple with first element of " + "type float must have all elements of type " + "float") + if tupType is not float and tupType is not int: + raise TypeError("'markevery' tuple contains an invalid type") + # Validate s against type list + elif isinstance(s, list): + if not all(isinstance(e, int) for e in s): + raise TypeError("'markevery' list must have all elements of " + "type int") # Validate s against type float int and None elif not isinstance(s, (float, int)): if s is not None: diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index c85c354d2b6a..51ea501474e2 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -338,22 +338,23 @@ def generate_validator_testcases(valid): (slice(2), slice(None, 2, None)), (slice(1, 2, 3), slice(1, 2, 3)) ), - 'fail': (((1, 2, 3), ValueError), - ([1, 2, 0.3], ValueError), - (['a', 2, 3], ValueError), - ([1, 2, 'a'], ValueError), - ((0.1, 0.2, 0.3), ValueError), - ((0.1, 2, 3), ValueError), - ((1, 0.2, 0.3), ValueError), - ((1, 0.1), ValueError), - ((0.1, 1), ValueError), - (('abc'), ValueError), - ((1, 'a'), ValueError), - ((0.1, 'b'), ValueError), - (('a', 1), ValueError), - (('a', 0.1), ValueError), + 'fail': (((1, 2, 3), TypeError), + ([1, 2, 0.3], TypeError), + (['a', 2, 3], TypeError), + ([1, 2, 'a'], TypeError), + ((0.1, 0.2, 0.3), TypeError), + ((0.1, 2, 3), TypeError), + ((1, 0.2, 0.3), TypeError), + ((1, 0.1), TypeError), + ((0.1, 1), TypeError), + (('abc'), TypeError), + ((1, 'a'), TypeError), + ((0.1, 'b'), TypeError), + (('a', 1), TypeError), + (('a', 0.1), TypeError), ('abc', TypeError), - ('a', TypeError) + ('a', TypeError), + (object(), TypeError) ) } )