From 17451e0b112a946d1ad8155ca3ed1474d14be474 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 29 Dec 2018 17:50:50 +0000 Subject: [PATCH 1/6] Use default colour cycle in more examples --- examples/lines_bars_and_markers/barh.py | 3 +-- examples/lines_bars_and_markers/broken_barh.py | 4 ++-- .../lines_bars_and_markers/eventcollection_demo.py | 10 +++++----- examples/lines_bars_and_markers/eventplot_demo.py | 9 ++------- examples/lines_bars_and_markers/joinstyle.py | 4 ++-- .../lines_bars_and_markers/markevery_prop_cycle.py | 6 +++--- examples/lines_bars_and_markers/scatter_with_legend.py | 2 +- examples/pyplots/fig_axes_customize_simple.py | 4 ++-- examples/pyplots/pyplot_two_subplots.py | 4 ++-- examples/text_labels_and_annotations/figlegend_demo.py | 4 ++-- 10 files changed, 22 insertions(+), 28 deletions(-) diff --git a/examples/lines_bars_and_markers/barh.py b/examples/lines_bars_and_markers/barh.py index 54b8fcb8a7cd..c537c0d9b215 100644 --- a/examples/lines_bars_and_markers/barh.py +++ b/examples/lines_bars_and_markers/barh.py @@ -21,8 +21,7 @@ performance = 3 + 10 * np.random.rand(len(people)) error = np.random.rand(len(people)) -ax.barh(y_pos, performance, xerr=error, align='center', - color='green', ecolor='black') +ax.barh(y_pos, performance, xerr=error, align='center') ax.set_yticks(y_pos) ax.set_yticklabels(people) ax.invert_yaxis() # labels read top-to-bottom diff --git a/examples/lines_bars_and_markers/broken_barh.py b/examples/lines_bars_and_markers/broken_barh.py index 72f2f90a9048..edf7b1eb31de 100644 --- a/examples/lines_bars_and_markers/broken_barh.py +++ b/examples/lines_bars_and_markers/broken_barh.py @@ -8,9 +8,9 @@ import matplotlib.pyplot as plt fig, ax = plt.subplots() -ax.broken_barh([(110, 30), (150, 10)], (10, 9), facecolors='blue') +ax.broken_barh([(110, 30), (150, 10)], (10, 9), facecolors='C0') ax.broken_barh([(10, 50), (100, 20), (130, 10)], (20, 9), - facecolors=('red', 'yellow', 'green')) + facecolors=('C1', 'C2', 'C3')) ax.set_ylim(5, 35) ax.set_xlim(0, 200) ax.set_xlabel('seconds since start') diff --git a/examples/lines_bars_and_markers/eventcollection_demo.py b/examples/lines_bars_and_markers/eventcollection_demo.py index 18c76fb135a0..897bb475c4bb 100644 --- a/examples/lines_bars_and_markers/eventcollection_demo.py +++ b/examples/lines_bars_and_markers/eventcollection_demo.py @@ -32,16 +32,16 @@ # plot the data fig = plt.figure() ax = fig.add_subplot(1, 1, 1) -ax.plot(xdata1, ydata1, 'r', xdata2, ydata2, 'b') +ax.plot(xdata1, ydata1, 'C0', xdata2, ydata2, 'C1') # create the events marking the x data points -xevents1 = EventCollection(xdata1, color=[1, 0, 0], linelength=0.05) -xevents2 = EventCollection(xdata2, color=[0, 0, 1], linelength=0.05) +xevents1 = EventCollection(xdata1, color='C0', linelength=0.05) +xevents2 = EventCollection(xdata2, color='C1', linelength=0.05) # create the events marking the y data points -yevents1 = EventCollection(ydata1, color=[1, 0, 0], linelength=0.05, +yevents1 = EventCollection(ydata1, color='C0', linelength=0.05, orientation='vertical') -yevents2 = EventCollection(ydata2, color=[0, 0, 1], linelength=0.05, +yevents2 = EventCollection(ydata2, color='C1', linelength=0.05, orientation='vertical') # add the events to the axis diff --git a/examples/lines_bars_and_markers/eventplot_demo.py b/examples/lines_bars_and_markers/eventplot_demo.py index 32e74c8ffe89..229d7937a448 100644 --- a/examples/lines_bars_and_markers/eventplot_demo.py +++ b/examples/lines_bars_and_markers/eventplot_demo.py @@ -20,12 +20,7 @@ data1 = np.random.random([6, 50]) # set different colors for each set of positions -colors1 = np.array([[1, 0, 0], - [0, 1, 0], - [0, 0, 1], - [1, 1, 0], - [1, 0, 1], - [0, 1, 1]]) +colors1 = ['C{}'.format(i) for i in range(6)] # set different line properties for each set of positions # note that some overlap @@ -49,7 +44,7 @@ # use individual values for the parameters this time # these values will be used for all data sets (except lineoffsets2, which # sets the increment between each data set in this usage) -colors2 = [[0, 0, 0]] +colors2 = 'k' lineoffsets2 = 1 linelengths2 = 1 diff --git a/examples/lines_bars_and_markers/joinstyle.py b/examples/lines_bars_and_markers/joinstyle.py index 7ac68883cfd4..f225dccee838 100644 --- a/examples/lines_bars_and_markers/joinstyle.py +++ b/examples/lines_bars_and_markers/joinstyle.py @@ -14,10 +14,10 @@ def plot_angle(ax, x, y, angle, style): phi = np.radians(angle) xx = [x + .5, x, x + .5*np.cos(phi)] yy = [y, y, y + .5*np.sin(phi)] - ax.plot(xx, yy, lw=8, color='blue', solid_joinstyle=style) + ax.plot(xx, yy, lw=8, color='C0', solid_joinstyle=style) ax.plot(xx[1:], yy[1:], lw=1, color='black') ax.plot(xx[1::-1], yy[1::-1], lw=1, color='black') - ax.plot(xx[1:2], yy[1:2], 'o', color='red', markersize=3) + ax.plot(xx[1:2], yy[1:2], 'o', color='C3', markersize=3) ax.text(x, y + .2, '%.0f degrees' % angle) fig, ax = plt.subplots() diff --git a/examples/lines_bars_and_markers/markevery_prop_cycle.py b/examples/lines_bars_and_markers/markevery_prop_cycle.py index ac020e1ba713..295de4756736 100644 --- a/examples/lines_bars_and_markers/markevery_prop_cycle.py +++ b/examples/lines_bars_and_markers/markevery_prop_cycle.py @@ -1,7 +1,7 @@ """ -================================================================= -Implemented support for prop_cycle property markevery in rcParams -================================================================= +========================================= +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 diff --git a/examples/lines_bars_and_markers/scatter_with_legend.py b/examples/lines_bars_and_markers/scatter_with_legend.py index 1327f5cd170b..83b66ee2e0e6 100644 --- a/examples/lines_bars_and_markers/scatter_with_legend.py +++ b/examples/lines_bars_and_markers/scatter_with_legend.py @@ -13,7 +13,7 @@ fig, ax = plt.subplots() -for color in ['red', 'green', 'blue']: +for color in ['C0', 'C1', 'C2']: n = 750 x, y = rand(2, n) scale = 200.0 * rand(n) diff --git a/examples/pyplots/fig_axes_customize_simple.py b/examples/pyplots/fig_axes_customize_simple.py index 9f1268a16a9d..508bd01a29dc 100644 --- a/examples/pyplots/fig_axes_customize_simple.py +++ b/examples/pyplots/fig_axes_customize_simple.py @@ -22,13 +22,13 @@ for label in ax1.xaxis.get_ticklabels(): # label is a Text instance - label.set_color('red') + label.set_color('C0') label.set_rotation(45) label.set_fontsize(16) for line in ax1.yaxis.get_ticklines(): # line is a Line2D instance - line.set_color('green') + line.set_color('C1') line.set_markersize(25) line.set_markeredgewidth(3) diff --git a/examples/pyplots/pyplot_two_subplots.py b/examples/pyplots/pyplot_two_subplots.py index 4578f096bbb4..fd2994b91245 100644 --- a/examples/pyplots/pyplot_two_subplots.py +++ b/examples/pyplots/pyplot_two_subplots.py @@ -16,10 +16,10 @@ def f(t): plt.figure() plt.subplot(211) -plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k') +plt.plot(t1, f(t1), 'C0o', t2, f(t2), 'k') plt.subplot(212) -plt.plot(t2, np.cos(2*np.pi*t2), 'r--') +plt.plot(t2, np.cos(2*np.pi*t2), 'C1--') plt.show() ############################################################################# diff --git a/examples/text_labels_and_annotations/figlegend_demo.py b/examples/text_labels_and_annotations/figlegend_demo.py index b8410d228e24..2e2cbf0b0a34 100644 --- a/examples/text_labels_and_annotations/figlegend_demo.py +++ b/examples/text_labels_and_annotations/figlegend_demo.py @@ -15,11 +15,11 @@ x = np.arange(0.0, 2.0, 0.02) y1 = np.sin(2 * np.pi * x) y2 = np.exp(-x) -l1, l2 = axs[0].plot(x, y1, 'rs-', x, y2, 'go') +l1, l2 = axs[0].plot(x, y1, 'C0s-', x, y2, 'C1o') y3 = np.sin(4 * np.pi * x) y4 = np.exp(-2 * x) -l3, l4 = axs[1].plot(x, y3, 'yd-', x, y4, 'k^') +l3, l4 = axs[1].plot(x, y3, 'C2d-', x, y4, 'C3^') fig.legend((l1, l2), ('Line 1', 'Line 2'), 'upper left') fig.legend((l3, l4), ('Line 3', 'Line 4'), 'upper right') From ab4c50473631c7bb9bdfaf070f7b34fd88d470e7 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Sat, 29 Dec 2018 21:55:51 +0000 Subject: [PATCH 2/6] Update examples/lines_bars_and_markers/eventplot_demo.py Co-Authored-By: dstansby --- examples/lines_bars_and_markers/eventplot_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/lines_bars_and_markers/eventplot_demo.py b/examples/lines_bars_and_markers/eventplot_demo.py index 229d7937a448..d1be2fbe91f1 100644 --- a/examples/lines_bars_and_markers/eventplot_demo.py +++ b/examples/lines_bars_and_markers/eventplot_demo.py @@ -44,7 +44,7 @@ # use individual values for the parameters this time # these values will be used for all data sets (except lineoffsets2, which # sets the increment between each data set in this usage) -colors2 = 'k' +colors2 = 'black' lineoffsets2 = 1 linelengths2 = 1 From b6b5e8e225675eaa2f3aa43eb5a09246fb5c55ec Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 29 Dec 2018 22:01:49 +0000 Subject: [PATCH 3/6] Use tab:color instead of CN notation --- examples/lines_bars_and_markers/broken_barh.py | 4 ++-- .../lines_bars_and_markers/eventcollection_demo.py | 10 +++++----- examples/lines_bars_and_markers/joinstyle.py | 5 +++-- examples/lines_bars_and_markers/scatter_with_legend.py | 2 +- examples/pyplots/fig_axes_customize_simple.py | 4 ++-- examples/pyplots/pyplot_two_subplots.py | 2 ++ 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/examples/lines_bars_and_markers/broken_barh.py b/examples/lines_bars_and_markers/broken_barh.py index edf7b1eb31de..c0691beaf255 100644 --- a/examples/lines_bars_and_markers/broken_barh.py +++ b/examples/lines_bars_and_markers/broken_barh.py @@ -8,9 +8,9 @@ import matplotlib.pyplot as plt fig, ax = plt.subplots() -ax.broken_barh([(110, 30), (150, 10)], (10, 9), facecolors='C0') +ax.broken_barh([(110, 30), (150, 10)], (10, 9), facecolors='tab:blue') ax.broken_barh([(10, 50), (100, 20), (130, 10)], (20, 9), - facecolors=('C1', 'C2', 'C3')) + facecolors=('tab:orange', 'tab:green', 'tab:red')) ax.set_ylim(5, 35) ax.set_xlim(0, 200) ax.set_xlabel('seconds since start') diff --git a/examples/lines_bars_and_markers/eventcollection_demo.py b/examples/lines_bars_and_markers/eventcollection_demo.py index 897bb475c4bb..bd89dee908c4 100644 --- a/examples/lines_bars_and_markers/eventcollection_demo.py +++ b/examples/lines_bars_and_markers/eventcollection_demo.py @@ -32,16 +32,16 @@ # plot the data fig = plt.figure() ax = fig.add_subplot(1, 1, 1) -ax.plot(xdata1, ydata1, 'C0', xdata2, ydata2, 'C1') +ax.plot(xdata1, ydata1, xdata2, ydata2) # create the events marking the x data points -xevents1 = EventCollection(xdata1, color='C0', linelength=0.05) -xevents2 = EventCollection(xdata2, color='C1', linelength=0.05) +xevents1 = EventCollection(xdata1, color='tab:blue', linelength=0.05) +xevents2 = EventCollection(xdata2, color='tab:orange', linelength=0.05) # create the events marking the y data points -yevents1 = EventCollection(ydata1, color='C0', linelength=0.05, +yevents1 = EventCollection(ydata1, color='tab:blue', linelength=0.05, orientation='vertical') -yevents2 = EventCollection(ydata2, color='C1', linelength=0.05, +yevents2 = EventCollection(ydata2, color='tab:orange', linelength=0.05, orientation='vertical') # add the events to the axis diff --git a/examples/lines_bars_and_markers/joinstyle.py b/examples/lines_bars_and_markers/joinstyle.py index f225dccee838..f1db93a4145a 100644 --- a/examples/lines_bars_and_markers/joinstyle.py +++ b/examples/lines_bars_and_markers/joinstyle.py @@ -14,12 +14,13 @@ def plot_angle(ax, x, y, angle, style): phi = np.radians(angle) xx = [x + .5, x, x + .5*np.cos(phi)] yy = [y, y, y + .5*np.sin(phi)] - ax.plot(xx, yy, lw=8, color='C0', solid_joinstyle=style) + ax.plot(xx, yy, lw=8, color='tab:blue', solid_joinstyle=style) ax.plot(xx[1:], yy[1:], lw=1, color='black') ax.plot(xx[1::-1], yy[1::-1], lw=1, color='black') - ax.plot(xx[1:2], yy[1:2], 'o', color='C3', markersize=3) + ax.plot(xx[1:2], yy[1:2], 'o', color='tab:red', markersize=3) ax.text(x, y + .2, '%.0f degrees' % angle) + fig, ax = plt.subplots() ax.set_title('Join style') diff --git a/examples/lines_bars_and_markers/scatter_with_legend.py b/examples/lines_bars_and_markers/scatter_with_legend.py index 83b66ee2e0e6..f7b7af5ac3b3 100644 --- a/examples/lines_bars_and_markers/scatter_with_legend.py +++ b/examples/lines_bars_and_markers/scatter_with_legend.py @@ -13,7 +13,7 @@ fig, ax = plt.subplots() -for color in ['C0', 'C1', 'C2']: +for color in ['tab:blue', 'tab:orange', 'tab:green']: n = 750 x, y = rand(2, n) scale = 200.0 * rand(n) diff --git a/examples/pyplots/fig_axes_customize_simple.py b/examples/pyplots/fig_axes_customize_simple.py index 508bd01a29dc..0d665b6a4747 100644 --- a/examples/pyplots/fig_axes_customize_simple.py +++ b/examples/pyplots/fig_axes_customize_simple.py @@ -22,13 +22,13 @@ for label in ax1.xaxis.get_ticklabels(): # label is a Text instance - label.set_color('C0') + label.set_color('tab:red') label.set_rotation(45) label.set_fontsize(16) for line in ax1.yaxis.get_ticklines(): # line is a Line2D instance - line.set_color('C1') + line.set_color('tab:green') line.set_markersize(25) line.set_markeredgewidth(3) diff --git a/examples/pyplots/pyplot_two_subplots.py b/examples/pyplots/pyplot_two_subplots.py index fd2994b91245..1319144fb51f 100644 --- a/examples/pyplots/pyplot_two_subplots.py +++ b/examples/pyplots/pyplot_two_subplots.py @@ -8,9 +8,11 @@ import numpy as np import matplotlib.pyplot as plt + def f(t): return np.exp(-t) * np.cos(2*np.pi*t) + t1 = np.arange(0.0, 5.0, 0.1) t2 = np.arange(0.0, 5.0, 0.02) From 1a10973da552a4bf061093da1106e375a7e6c624 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 3 Jan 2019 14:23:38 +0000 Subject: [PATCH 4/6] Replace multiple plots in one line calls --- examples/lines_bars_and_markers/eventcollection_demo.py | 3 ++- examples/pyplots/pyplot_two_subplots.py | 5 +++-- examples/text_labels_and_annotations/figlegend_demo.py | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/lines_bars_and_markers/eventcollection_demo.py b/examples/lines_bars_and_markers/eventcollection_demo.py index bd89dee908c4..abdb6e6c05f5 100644 --- a/examples/lines_bars_and_markers/eventcollection_demo.py +++ b/examples/lines_bars_and_markers/eventcollection_demo.py @@ -32,7 +32,8 @@ # plot the data fig = plt.figure() ax = fig.add_subplot(1, 1, 1) -ax.plot(xdata1, ydata1, xdata2, ydata2) +ax.plot(xdata1, ydata1, color='tab:blue') +ax.plot(xdata2, ydata2, color='tab:orange') # create the events marking the x data points xevents1 = EventCollection(xdata1, color='tab:blue', linelength=0.05) diff --git a/examples/pyplots/pyplot_two_subplots.py b/examples/pyplots/pyplot_two_subplots.py index 1319144fb51f..0f606603150a 100644 --- a/examples/pyplots/pyplot_two_subplots.py +++ b/examples/pyplots/pyplot_two_subplots.py @@ -18,10 +18,11 @@ def f(t): plt.figure() plt.subplot(211) -plt.plot(t1, f(t1), 'C0o', t2, f(t2), 'k') +plot.plot(t1, f(t1), color='tab:blue', marker='o') +plt.plot(t2, f(t2), color='black') plt.subplot(212) -plt.plot(t2, np.cos(2*np.pi*t2), 'C1--') +plt.plot(t2, np.cos(2*np.pi*t2), color='tab:orange', linestyle='--') plt.show() ############################################################################# diff --git a/examples/text_labels_and_annotations/figlegend_demo.py b/examples/text_labels_and_annotations/figlegend_demo.py index 2e2cbf0b0a34..674b7627f09f 100644 --- a/examples/text_labels_and_annotations/figlegend_demo.py +++ b/examples/text_labels_and_annotations/figlegend_demo.py @@ -15,11 +15,13 @@ x = np.arange(0.0, 2.0, 0.02) y1 = np.sin(2 * np.pi * x) y2 = np.exp(-x) -l1, l2 = axs[0].plot(x, y1, 'C0s-', x, y2, 'C1o') +l1, = axs[0].plot(x, y1) +l2, = axs[0].plot(x, y2, marker='o') y3 = np.sin(4 * np.pi * x) y4 = np.exp(-2 * x) -l3, l4 = axs[1].plot(x, y3, 'C2d-', x, y4, 'C3^') +l3, = axs[1].plot(x, y3, color='tab:green') +l4, = axs[1].plot(x, y4, color='tab:red', marker='^') fig.legend((l1, l2), ('Line 1', 'Line 2'), 'upper left') fig.legend((l3, l4), ('Line 3', 'Line 4'), 'upper right') From 63a209e7264a985395fe922b22bf41e60a8048fc Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 4 Jan 2019 12:50:43 +0000 Subject: [PATCH 5/6] Fix plot > plt --- examples/pyplots/pyplot_two_subplots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pyplots/pyplot_two_subplots.py b/examples/pyplots/pyplot_two_subplots.py index 0f606603150a..8c6453477b21 100644 --- a/examples/pyplots/pyplot_two_subplots.py +++ b/examples/pyplots/pyplot_two_subplots.py @@ -18,7 +18,7 @@ def f(t): plt.figure() plt.subplot(211) -plot.plot(t1, f(t1), color='tab:blue', marker='o') +plt.plot(t1, f(t1), color='tab:blue', marker='o') plt.plot(t2, f(t2), color='black') plt.subplot(212) From 9bd8f81eed737a5cce089bef684c73c4e001030a Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 5 Jan 2019 13:25:31 +0000 Subject: [PATCH 6/6] Fix flake8 error ignoring --- .flake8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.flake8 b/.flake8 index 4cb738b4b544..1073244a2de8 100644 --- a/.flake8 +++ b/.flake8 @@ -185,7 +185,7 @@ per-file-ignores = examples/pyplots/pyplot_simple.py: E231, E402 examples/pyplots/pyplot_text.py: E402 examples/pyplots/pyplot_three.py: E402 - examples/pyplots/pyplot_two_subplots.py: E302, E402 + examples/pyplots/pyplot_two_subplots.py: E402 examples/pyplots/text_commands.py: E231, E402 examples/pyplots/text_layout.py: E231, E402 examples/pyplots/whats_new_1_subplot3d.py: E402