From 308fae57e3b84407e963e2ef6fb76a794649e7b4 Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Sat, 7 Mar 2015 13:15:50 -1000 Subject: [PATCH] Plot: convert 'c' to 'color' immediately; closes #4162, #4157 --- lib/matplotlib/axes/_axes.py | 6 ++++++ lib/matplotlib/tests/test_axes.py | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 94cda34a29d0..fb82fd59b256 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -1366,6 +1366,12 @@ def plot(self, *args, **kwargs): self.cla() lines = [] + # Convert "c" alias to "color" immediately, to avoid + # confusion farther on. + c = kwargs.pop('c', None) + if c is not None: + kwargs['color'] = c + for line in self._get_lines(*args, **kwargs): self.add_line(line) lines.append(line) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 22607650182f..db170440d221 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3492,10 +3492,10 @@ def test_set_get_ticklabels(): # set ticklabel to 1 plot in normal way ax[0].set_xticklabels(('a', 'b', 'c', 'd')) ax[0].set_yticklabels(('11', '12', '13', '14')) - + # set ticklabel to the other plot, expect the 2 plots have same label setting - # pass get_ticklabels return value as ticklabels argument - ax[1].set_xticklabels(ax[0].get_xticklabels() ) + # pass get_ticklabels return value as ticklabels argument + ax[1].set_xticklabels(ax[0].get_xticklabels() ) ax[1].set_yticklabels(ax[0].get_yticklabels() ) @@ -3545,11 +3545,18 @@ def test_color_None(): fig, ax = plt.subplots() ax.plot([1,2], [1,2], color=None) +@cleanup +def test_color_alias(): + # issues 4157 and 4162 + fig, ax = plt.subplots() + line = ax.plot([0, 1], c='lime')[0] + assert_equal('lime', line.get_color()) + @cleanup def test_numerical_hist_label(): fig, ax = plt.subplots() ax.hist([range(15)] * 5, label=range(5)) - + @cleanup def test_move_offsetlabel(): data = np.random.random(10) * 1e-22