From 2b5ea43f568fa2b50da165242eab6fc1e364c8ab Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 10 Dec 2016 11:16:15 +0000 Subject: [PATCH 1/4] Fix eventplot where zero-length arrays are given for some properties --- lib/matplotlib/axes/_axes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 194667346c26..889b14b4da9a 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -1187,9 +1187,9 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1, if len(linelengths) == 0: linelengths = [None] if len(linewidths) == 0: - lineoffsets = [None] - if len(linewidths) == 0: - lineoffsets = [None] + linewidths = [None] + if len(linestyles) == 0: + linestyles = [None] if len(colors) == 0: colors = [None] From c739dd56292b589431f2bf20b1ec7dd6a3626a03 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 10 Dec 2016 11:29:06 +0000 Subject: [PATCH 2/4] Set line properties to defaults instead of None --- lib/matplotlib/axes/_axes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 889b14b4da9a..4600e9c24e37 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -1183,13 +1183,13 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1, linewidths = np.asarray(linewidths) if len(lineoffsets) == 0: - lineoffsets = [None] + lineoffsets = [0] if len(linelengths) == 0: - linelengths = [None] + linelengths = [1] if len(linewidths) == 0: linewidths = [None] if len(linestyles) == 0: - linestyles = [None] + linestyles = ['solid'] if len(colors) == 0: colors = [None] From bcedb0173de80a825ef0ad0c84bcff2840ea394e Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 10 Dec 2016 11:29:28 +0000 Subject: [PATCH 3/4] Add test for zero length arguments to eventplot --- lib/matplotlib/tests/test_axes.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 355ef9b5ea7f..63214779ba25 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -2770,6 +2770,13 @@ def test_empty_eventplot(): plt.draw() +@cleanup +def test_eventplot_empty_args(): + fig, ax = plt.subplots() + ax.eventplot([1, 2, 3], lineoffsets=[], linelengths=[], linewidths=[], + linestyles=[], colors=[]) + + @image_comparison(baseline_images=['marker_styles'], extensions=['png'], remove_text=True) def test_marker_styles(): fig = plt.figure() From 775c6f09dbe0e442dfb88ca6e502a9a1b7b6573b Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 10 Dec 2016 11:44:46 +0000 Subject: [PATCH 4/4] Document what happens when zero length arrays are passed to eventplot --- lib/matplotlib/axes/_axes.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 4600e9c24e37..d430d488e997 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -1110,10 +1110,12 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1, "vertical' : lines will be horizontal and arranged in columns *lineoffsets* : - A float or array-like containing floats. + A float or array-like containing floats. If a zero length array, + defaults to 0. *linelengths* : - A float or array-like containing floats. + A float or array-like containing floats. If a zero length array, + defaults to 1. *linewidths* : A float or array-like containing floats. @@ -1124,7 +1126,7 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1, *linestyles* : [ 'solid' | 'dashed' | 'dashdot' | 'dotted' ] or an array of these - values + values. If a zero length array, defaults to 'solid'. For linelengths, linewidths, colors, and linestyles, if only a single value is given, that value is applied to all lines. If an array-like