From 293474080f78355c10a67680f0cf518fd1dbee7f Mon Sep 17 00:00:00 2001 From: Adrien VINCENT Date: Wed, 25 May 2016 12:04:39 +0200 Subject: [PATCH 01/13] Add a common example to compare style sheets --- .../style_sheets/style_sheets_reference.py | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 examples/style_sheets/style_sheets_reference.py diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py new file mode 100644 index 000000000000..fe79f3a8794d --- /dev/null +++ b/examples/style_sheets/style_sheets_reference.py @@ -0,0 +1,119 @@ +""" +This example demonstrates different available style sheets on a common example. + +The different plots are heavily similar to the other ones in the style sheet +gallery. +""" +import numpy as np +import matplotlib.pyplot as plt + +def plot_scatter(ax, prng, nb_samples=200): + """ Scatter plot. + + NB: `plt.scatter` doesn't use default colors. + """ + x, y = prng.normal(size=(2, nb_samples)) + ax.plot(x, y, 'o') + return ax + +def plot_colored_sinusoidal_lines(ax): + """ Plot sinusoidal lines with colors from default color cycle. + """ + L = 2*np.pi + x = np.linspace(0, L) + ncolors = len(plt.rcParams['axes.color_cycle']) + shift = np.linspace(0, L, ncolors, endpoint=False) + for s in shift: + ax.plot(x, np.sin(x + s), '-') + ax.margins(0) + return ax + +def plot_bar_graphs(ax, prng, min_value=5, max_value=25, nb_samples=5): + """ Plot two bar graphs side by side, with letters as xticklabels. + """ + x = np.arange(nb_samples) + ya, yb = prng.randint(min_value, max_value, size=(2, nb_samples)) + width = 0.25 + ax.bar(x, ya, width) + ax.bar(x + width, yb, width, color=plt.rcParams['axes.color_cycle'][2]) + ax.set_xticks(x + width) + ax.set_xticklabels(['a', 'b', 'c', 'd', 'e']) + return ax + +def plot_colored_circles(ax, prng, nb_samples=15): + """ Plot circle patches. + + NB: drawing a fixed amount of samples, rather than using the length of + the color cycle, because different styles may have different numbers of + colors. + """ + max_idx = max(nb_samples, len(plt.rcParams['axes.color_cycle'])) + for color in plt.rcParams['axes.color_cycle'][0:max_idx]: + ax.add_patch(plt.Circle(prng.normal(scale=3, size=2), + radius=1.0, color=color)) + # Force the limits to be the same accross the styles (because different + # styles may have different numbers of available colors). + ax.set_xlim([-5., 7.]) + ax.set_ylim([-8.5, 3.5]) + ax.set_aspect('equal', adjustable='box') # to plot circles as circles + return ax + +def plot_image_and_patch(ax, prng, size=(20, 20)): + """ Plot an image with random values and superimpose a circular patch. + """ + values = prng.random_sample(size=size) + ax.imshow(values, interpolation='none') + c = plt.Circle((5, 5), radius=5, label='patch') + ax.add_patch(c) + +def plot_histograms(ax, prng, nb_samples=10000): + """ Plot 4 histograms and a text annotation. + """ + params = ((10, 10), (4, 12), (50, 12), (6, 55)) + for values in (prng.beta(a, b, size=nb_samples) for a, b in params): + ax.hist(values, histtype="stepfilled", bins=30, alpha=0.8, normed=True) + # Add a small annotation + ax.annotate('Annotation', xy=(0.25, 4.25), xycoords='data', + xytext=(0.4, 10), textcoords='data', + bbox=dict(boxstyle="round", alpha=0.2), + arrowprops=dict(arrowstyle="->", + connectionstyle= + "angle,angleA=-95,angleB=35,rad=10"), + ) + return ax + +def plot_figure(style_label=None): + """ + Setup and plot the demonstration figure with the style `style_label`. + If `style_label`, fall back to the `default` style. + """ + if style_label == None: + style_label = 'default' + + # Use a dedicated RandomState instance to draw the same "random" values across + # the different figures + prng = np.random.RandomState(145236987) + + fig, axes = plt.subplots(ncols=3, nrows=2, num=style_label) + fig.suptitle(style_label) + + axes_list = axes.ravel() # for convenience + plot_scatter(axes_list[0], prng) + plot_image_and_patch(axes_list[1], prng) + plot_bar_graphs(axes_list[2], prng) + plot_colored_circles(axes_list[3], prng) + plot_colored_sinusoidal_lines(axes_list[4]) + plot_histograms(axes_list[5], prng) + + return fig + + +if __name__ == "__main__": + + # Plot a demonstration figure for every available style sheet. + for style_label in plt.style.available: + with plt.style.context(style_label): + fig = plot_figure(style_label=style_label) + + plt.show() + From 9eec6d6820c03004c2168deaeaaf6683b6b239c8 Mon Sep 17 00:00:00 2001 From: Adrien VINCENT Date: Wed, 25 May 2016 15:48:34 +0200 Subject: [PATCH 02/13] PEP8 fixes and add labels in 1st subplot --- examples/style_sheets/style_sheets_reference.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index fe79f3a8794d..afe104d6fc46 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -7,6 +7,7 @@ import numpy as np import matplotlib.pyplot as plt + def plot_scatter(ax, prng, nb_samples=200): """ Scatter plot. @@ -14,8 +15,11 @@ def plot_scatter(ax, prng, nb_samples=200): """ x, y = prng.normal(size=(2, nb_samples)) ax.plot(x, y, 'o') + ax.set_xlabel('X-label') + ax.set_ylabel('Y-label') return ax + def plot_colored_sinusoidal_lines(ax): """ Plot sinusoidal lines with colors from default color cycle. """ @@ -28,6 +32,7 @@ def plot_colored_sinusoidal_lines(ax): ax.margins(0) return ax + def plot_bar_graphs(ax, prng, min_value=5, max_value=25, nb_samples=5): """ Plot two bar graphs side by side, with letters as xticklabels. """ @@ -40,6 +45,7 @@ def plot_bar_graphs(ax, prng, min_value=5, max_value=25, nb_samples=5): ax.set_xticklabels(['a', 'b', 'c', 'd', 'e']) return ax + def plot_colored_circles(ax, prng, nb_samples=15): """ Plot circle patches. @@ -58,6 +64,7 @@ def plot_colored_circles(ax, prng, nb_samples=15): ax.set_aspect('equal', adjustable='box') # to plot circles as circles return ax + def plot_image_and_patch(ax, prng, size=(20, 20)): """ Plot an image with random values and superimpose a circular patch. """ @@ -66,6 +73,7 @@ def plot_image_and_patch(ax, prng, size=(20, 20)): c = plt.Circle((5, 5), radius=5, label='patch') ax.add_patch(c) + def plot_histograms(ax, prng, nb_samples=10000): """ Plot 4 histograms and a text annotation. """ @@ -82,12 +90,13 @@ def plot_histograms(ax, prng, nb_samples=10000): ) return ax + def plot_figure(style_label=None): - """ + """ Setup and plot the demonstration figure with the style `style_label`. If `style_label`, fall back to the `default` style. """ - if style_label == None: + if style_label is None: style_label = 'default' # Use a dedicated RandomState instance to draw the same "random" values across @@ -116,4 +125,3 @@ def plot_figure(style_label=None): fig = plot_figure(style_label=style_label) plt.show() - From a56734fe337ab292e198af0ac20c71c01e0463ae Mon Sep 17 00:00:00 2001 From: Adrien VINCENT Date: Wed, 25 May 2016 18:08:25 +0200 Subject: [PATCH 03/13] Fix remaining PEP8 issues --- examples/style_sheets/style_sheets_reference.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index afe104d6fc46..6ea53f1dbddb 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -84,9 +84,9 @@ def plot_histograms(ax, prng, nb_samples=10000): ax.annotate('Annotation', xy=(0.25, 4.25), xycoords='data', xytext=(0.4, 10), textcoords='data', bbox=dict(boxstyle="round", alpha=0.2), - arrowprops=dict(arrowstyle="->", - connectionstyle= - "angle,angleA=-95,angleB=35,rad=10"), + arrowprops=dict( + arrowstyle="->", + connectionstyle="angle,angleA=-95,angleB=35,rad=10"), ) return ax @@ -99,8 +99,8 @@ def plot_figure(style_label=None): if style_label is None: style_label = 'default' - # Use a dedicated RandomState instance to draw the same "random" values across - # the different figures + # Use a dedicated RandomState instance to draw the same "random" values + # across the different figures prng = np.random.RandomState(145236987) fig, axes = plt.subplots(ncols=3, nrows=2, num=style_label) From 671f4674e9df8e0239b664e73c526817a89e7403 Mon Sep 17 00:00:00 2001 From: Adrien VINCENT Date: Fri, 27 May 2016 20:12:39 +0200 Subject: [PATCH 04/13] rely on rcParams['axes.prop_cycle'] to iterate over the colors --- examples/style_sheets/style_sheets_reference.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index 6ea53f1dbddb..6ec6bfe97d18 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -53,8 +53,9 @@ def plot_colored_circles(ax, prng, nb_samples=15): the color cycle, because different styles may have different numbers of colors. """ - max_idx = max(nb_samples, len(plt.rcParams['axes.color_cycle'])) - for color in plt.rcParams['axes.color_cycle'][0:max_idx]: + list_of_colors = plt.rcParams['axes.prop_cycle'].by_key()['color'] + max_idx = min(nb_samples, len(list_of_colors)) + for color in list_of_colors[0:max_idx]: ax.add_patch(plt.Circle(prng.normal(scale=3, size=2), radius=1.0, color=color)) # Force the limits to be the same accross the styles (because different From 50a516e2d7a143ba0fdc7d80f2fa2bab5876c700 Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Sat, 28 May 2016 23:54:35 +0200 Subject: [PATCH 05/13] Docstrings corrections/Code clarification/Add a 2nd scatter cloud --- .../style_sheets/style_sheets_reference.py | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index 6ec6bfe97d18..f1d5cca0d862 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -8,13 +8,12 @@ import matplotlib.pyplot as plt -def plot_scatter(ax, prng, nb_samples=200): +def plot_scatter(ax, prng, nb_samples=100): """ Scatter plot. - - NB: `plt.scatter` doesn't use default colors. """ - x, y = prng.normal(size=(2, nb_samples)) - ax.plot(x, y, 'o') + for mu, sigma, marker in [(-.5, 0.75, 'o'), (0.75, 1., 's')]: + x, y = prng.normal(loc=mu, scale=sigma, size=(2, nb_samples)) + ax.plot(x, y, marker=marker, ls='') ax.set_xlabel('X-label') ax.set_ylabel('Y-label') return ax @@ -25,8 +24,8 @@ def plot_colored_sinusoidal_lines(ax): """ L = 2*np.pi x = np.linspace(0, L) - ncolors = len(plt.rcParams['axes.color_cycle']) - shift = np.linspace(0, L, ncolors, endpoint=False) + nb_colors = len(plt.rcParams['axes.prop_cycle']) + shift = np.linspace(0, L, nb_colors, endpoint=False) for s in shift: ax.plot(x, np.sin(x + s), '-') ax.margins(0) @@ -40,7 +39,7 @@ def plot_bar_graphs(ax, prng, min_value=5, max_value=25, nb_samples=5): ya, yb = prng.randint(min_value, max_value, size=(2, nb_samples)) width = 0.25 ax.bar(x, ya, width) - ax.bar(x + width, yb, width, color=plt.rcParams['axes.color_cycle'][2]) + ax.bar(x + width, yb, width, color='C2') ax.set_xticks(x + width) ax.set_xticklabels(['a', 'b', 'c', 'd', 'e']) return ax @@ -53,15 +52,13 @@ def plot_colored_circles(ax, prng, nb_samples=15): the color cycle, because different styles may have different numbers of colors. """ - list_of_colors = plt.rcParams['axes.prop_cycle'].by_key()['color'] - max_idx = min(nb_samples, len(list_of_colors)) - for color in list_of_colors[0:max_idx]: + for sty_dict, j in zip(plt.rcParams['axes.prop_cycle'], range(nb_samples)): ax.add_patch(plt.Circle(prng.normal(scale=3, size=2), - radius=1.0, color=color)) - # Force the limits to be the same accross the styles (because different + radius=1.0, color=sty_dict['color'])) + # Force the limits to be the same across the styles (because different # styles may have different numbers of available colors). - ax.set_xlim([-5., 7.]) - ax.set_ylim([-8.5, 3.5]) + ax.set_xlim([-4, 7]) + ax.set_ylim([-5, 6]) ax.set_aspect('equal', adjustable='box') # to plot circles as circles return ax @@ -79,9 +76,10 @@ def plot_histograms(ax, prng, nb_samples=10000): """ Plot 4 histograms and a text annotation. """ params = ((10, 10), (4, 12), (50, 12), (6, 55)) - for values in (prng.beta(a, b, size=nb_samples) for a, b in params): + for a, b in params: + values = prng.beta(a, b, size=nb_samples) ax.hist(values, histtype="stepfilled", bins=30, alpha=0.8, normed=True) - # Add a small annotation + # Add a small annotation. ax.annotate('Annotation', xy=(0.25, 4.25), xycoords='data', xytext=(0.4, 10), textcoords='data', bbox=dict(boxstyle="round", alpha=0.2), @@ -95,25 +93,24 @@ def plot_histograms(ax, prng, nb_samples=10000): def plot_figure(style_label=None): """ Setup and plot the demonstration figure with the style `style_label`. - If `style_label`, fall back to the `default` style. + If `style_label` is None, fall back to the `default` style. """ if style_label is None: style_label = 'default' # Use a dedicated RandomState instance to draw the same "random" values - # across the different figures - prng = np.random.RandomState(145236987) + # across the different figures. + prng = np.random.RandomState(96917002) fig, axes = plt.subplots(ncols=3, nrows=2, num=style_label) fig.suptitle(style_label) - axes_list = axes.ravel() # for convenience - plot_scatter(axes_list[0], prng) - plot_image_and_patch(axes_list[1], prng) - plot_bar_graphs(axes_list[2], prng) - plot_colored_circles(axes_list[3], prng) - plot_colored_sinusoidal_lines(axes_list[4]) - plot_histograms(axes_list[5], prng) + plot_scatter(axes[0, 0], prng) + plot_image_and_patch(axes[0, 1], prng) + plot_bar_graphs(axes[0, 2], prng) + plot_colored_circles(axes[1, 0], prng) + plot_colored_sinusoidal_lines(axes[1, 1]) + plot_histograms(axes[1, 2], prng) return fig From d9da90cffa2487b1c917ea5bbc51820c479a132a Mon Sep 17 00:00:00 2001 From: Adrien VINCENT Date: Mon, 5 Sep 2016 10:28:19 +0200 Subject: [PATCH 06/13] Fix typos, use more clever annotation position and use tight_layout --- .../style_sheets/style_sheets_reference.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index f1d5cca0d862..657588847e9c 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -4,6 +4,7 @@ The different plots are heavily similar to the other ones in the style sheet gallery. """ + import numpy as np import matplotlib.pyplot as plt @@ -13,14 +14,14 @@ def plot_scatter(ax, prng, nb_samples=100): """ for mu, sigma, marker in [(-.5, 0.75, 'o'), (0.75, 1., 's')]: x, y = prng.normal(loc=mu, scale=sigma, size=(2, nb_samples)) - ax.plot(x, y, marker=marker, ls='') + ax.plot(x, y, ls='none', marker=marker) ax.set_xlabel('X-label') ax.set_ylabel('Y-label') return ax def plot_colored_sinusoidal_lines(ax): - """ Plot sinusoidal lines with colors from default color cycle. + """ Plots sinusoidal lines with colors following the style color cycle. """ L = 2*np.pi x = np.linspace(0, L) @@ -33,7 +34,7 @@ def plot_colored_sinusoidal_lines(ax): def plot_bar_graphs(ax, prng, min_value=5, max_value=25, nb_samples=5): - """ Plot two bar graphs side by side, with letters as xticklabels. + """ Plots two bar graphs side by side, with letters as xticklabels. """ x = np.arange(nb_samples) ya, yb = prng.randint(min_value, max_value, size=(2, nb_samples)) @@ -46,11 +47,11 @@ def plot_bar_graphs(ax, prng, min_value=5, max_value=25, nb_samples=5): def plot_colored_circles(ax, prng, nb_samples=15): - """ Plot circle patches. + """ Plots circle patches. - NB: drawing a fixed amount of samples, rather than using the length of - the color cycle, because different styles may have different numbers of - colors. + NB: draws a fixed amount of samples, rather than using the length of + the color cycle, because different styles may have different numbers + of colors. """ for sty_dict, j in zip(plt.rcParams['axes.prop_cycle'], range(nb_samples)): ax.add_patch(plt.Circle(prng.normal(scale=3, size=2), @@ -64,7 +65,7 @@ def plot_colored_circles(ax, prng, nb_samples=15): def plot_image_and_patch(ax, prng, size=(20, 20)): - """ Plot an image with random values and superimpose a circular patch. + """ Plots an image with random values and superimposes a circular patch. """ values = prng.random_sample(size=size) ax.imshow(values, interpolation='none') @@ -73,7 +74,7 @@ def plot_image_and_patch(ax, prng, size=(20, 20)): def plot_histograms(ax, prng, nb_samples=10000): - """ Plot 4 histograms and a text annotation. + """ Plots 4 histograms and a text annotation. """ params = ((10, 10), (4, 12), (50, 12), (6, 55)) for a, b in params: @@ -81,7 +82,8 @@ def plot_histograms(ax, prng, nb_samples=10000): ax.hist(values, histtype="stepfilled", bins=30, alpha=0.8, normed=True) # Add a small annotation. ax.annotate('Annotation', xy=(0.25, 4.25), xycoords='data', - xytext=(0.4, 10), textcoords='data', + xytext=(0.9, 0.9), textcoords='axes fraction', + va="top", ha="right", bbox=dict(boxstyle="round", alpha=0.2), arrowprops=dict( arrowstyle="->", @@ -92,7 +94,7 @@ def plot_histograms(ax, prng, nb_samples=10000): def plot_figure(style_label=None): """ - Setup and plot the demonstration figure with the style `style_label`. + Sets up and plots the demonstration figure with the style `style_label`. If `style_label` is None, fall back to the `default` style. """ if style_label is None: @@ -112,6 +114,8 @@ def plot_figure(style_label=None): plot_colored_sinusoidal_lines(axes[1, 1]) plot_histograms(axes[1, 2], prng) + fig.tight_layout() + return fig From edaa9e83716b79be85102fdab0e91ca8121e74b3 Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Mon, 5 Sep 2016 20:46:53 +0200 Subject: [PATCH 07/13] Fix the docstrings to be more PEP257-compliant --- examples/style_sheets/style_sheets_reference.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index 657588847e9c..9946bd32d4ca 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -10,7 +10,7 @@ def plot_scatter(ax, prng, nb_samples=100): - """ Scatter plot. + """Scatter plot. """ for mu, sigma, marker in [(-.5, 0.75, 'o'), (0.75, 1., 's')]: x, y = prng.normal(loc=mu, scale=sigma, size=(2, nb_samples)) @@ -21,7 +21,7 @@ def plot_scatter(ax, prng, nb_samples=100): def plot_colored_sinusoidal_lines(ax): - """ Plots sinusoidal lines with colors following the style color cycle. + """Plot sinusoidal lines with colors following the style color cycle. """ L = 2*np.pi x = np.linspace(0, L) @@ -34,7 +34,7 @@ def plot_colored_sinusoidal_lines(ax): def plot_bar_graphs(ax, prng, min_value=5, max_value=25, nb_samples=5): - """ Plots two bar graphs side by side, with letters as xticklabels. + """Plot two bar graphs side by side, with letters as x-tick labels. """ x = np.arange(nb_samples) ya, yb = prng.randint(min_value, max_value, size=(2, nb_samples)) @@ -47,7 +47,7 @@ def plot_bar_graphs(ax, prng, min_value=5, max_value=25, nb_samples=5): def plot_colored_circles(ax, prng, nb_samples=15): - """ Plots circle patches. + """Plot circle patches. NB: draws a fixed amount of samples, rather than using the length of the color cycle, because different styles may have different numbers @@ -65,7 +65,7 @@ def plot_colored_circles(ax, prng, nb_samples=15): def plot_image_and_patch(ax, prng, size=(20, 20)): - """ Plots an image with random values and superimposes a circular patch. + """Plot an image with random values and superimpose a circular patch. """ values = prng.random_sample(size=size) ax.imshow(values, interpolation='none') @@ -74,7 +74,7 @@ def plot_image_and_patch(ax, prng, size=(20, 20)): def plot_histograms(ax, prng, nb_samples=10000): - """ Plots 4 histograms and a text annotation. + """Plot 4 histograms and a text annotation. """ params = ((10, 10), (4, 12), (50, 12), (6, 55)) for a, b in params: @@ -93,8 +93,8 @@ def plot_histograms(ax, prng, nb_samples=10000): def plot_figure(style_label=None): - """ - Sets up and plots the demonstration figure with the style `style_label`. + """Setup and plot the demonstration figure with a given style. + If `style_label` is None, fall back to the `default` style. """ if style_label is None: From c56bcdd64091d6809de2a2b8cea1896489ec894f Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Sun, 16 Oct 2016 12:05:57 +0200 Subject: [PATCH 08/13] Switch to a single row of demo plots --- .../style_sheets/style_sheets_reference.py | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index 9946bd32d4ca..6a7c5486f137 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -16,7 +16,6 @@ def plot_scatter(ax, prng, nb_samples=100): x, y = prng.normal(loc=mu, scale=sigma, size=(2, nb_samples)) ax.plot(x, y, ls='none', marker=marker) ax.set_xlabel('X-label') - ax.set_ylabel('Y-label') return ax @@ -104,15 +103,22 @@ def plot_figure(style_label=None): # across the different figures. prng = np.random.RandomState(96917002) - fig, axes = plt.subplots(ncols=3, nrows=2, num=style_label) - fig.suptitle(style_label) - - plot_scatter(axes[0, 0], prng) - plot_image_and_patch(axes[0, 1], prng) - plot_bar_graphs(axes[0, 2], prng) - plot_colored_circles(axes[1, 0], prng) - plot_colored_sinusoidal_lines(axes[1, 1]) - plot_histograms(axes[1, 2], prng) + # Tweak the figure size to be better suited for a row of numerous plots: + # double the width and halve the height. NB: use relative changes because + # some styles may have a figure size different from the default one. + (fig_width, fig_height) = plt.rcParams['figure.figsize'] + fig_size = [fig_width * 2, fig_height / 2] + + fig, axes = plt.subplots(ncols=6, nrows=1, num=style_label, + figsize=fig_size, squeeze=True) + axes[0].set_ylabel(style_label) + + plot_scatter(axes[0], prng) + plot_image_and_patch(axes[1], prng) + plot_bar_graphs(axes[2], prng) + plot_colored_circles(axes[3], prng) + plot_colored_sinusoidal_lines(axes[4]) + plot_histograms(axes[5], prng) fig.tight_layout() From 5bf87dd09ed53d5fc7b40bd4b5f7e395f7773511 Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Sun, 16 Oct 2016 12:18:10 +0200 Subject: [PATCH 09/13] Cosmeticks tweaks --- examples/style_sheets/style_sheets_reference.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index 6a7c5486f137..ee1663e8e88b 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -22,13 +22,13 @@ def plot_scatter(ax, prng, nb_samples=100): def plot_colored_sinusoidal_lines(ax): """Plot sinusoidal lines with colors following the style color cycle. """ - L = 2*np.pi + L = 2 * np.pi x = np.linspace(0, L) nb_colors = len(plt.rcParams['axes.prop_cycle']) shift = np.linspace(0, L, nb_colors, endpoint=False) for s in shift: ax.plot(x, np.sin(x + s), '-') - ax.margins(0) + ax.set_xlim([x[0], x[-1]]) return ax @@ -57,7 +57,7 @@ def plot_colored_circles(ax, prng, nb_samples=15): radius=1.0, color=sty_dict['color'])) # Force the limits to be the same across the styles (because different # styles may have different numbers of available colors). - ax.set_xlim([-4, 7]) + ax.set_xlim([-4, 8]) ax.set_ylim([-5, 6]) ax.set_aspect('equal', adjustable='box') # to plot circles as circles return ax @@ -70,6 +70,9 @@ def plot_image_and_patch(ax, prng, size=(20, 20)): ax.imshow(values, interpolation='none') c = plt.Circle((5, 5), radius=5, label='patch') ax.add_patch(c) + # Remove ticks + ax.set_xticks([]) + ax.set_yticks([]) def plot_histograms(ax, prng, nb_samples=10000): From 828bec2baf5d5470875918c3d6d46e9ff5c38477 Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Sun, 16 Oct 2016 12:26:13 +0200 Subject: [PATCH 10/13] Switch script docstring to sphinx-gallery style --- examples/style_sheets/style_sheets_reference.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index ee1663e8e88b..ddd7c7691d23 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -1,8 +1,12 @@ """ -This example demonstrates different available style sheets on a common example. +====================== +Style sheets reference +====================== + +This scripts demonstrates the different available style sheets on a +common set of example plots: scatter plot, image, bar graph, patches, +line plot and histogram, -The different plots are heavily similar to the other ones in the style sheet -gallery. """ import numpy as np From 42bbad5eb69dbe171066c356330d88ea3c10feef Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Mon, 17 Oct 2016 00:33:40 +0200 Subject: [PATCH 11/13] Add 'default' and group styles ~ in lexicographic order --- examples/style_sheets/style_sheets_reference.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index ddd7c7691d23..b8c6fd41ec72 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -134,8 +134,17 @@ def plot_figure(style_label=None): if __name__ == "__main__": + # Setup a list of all available styles, in alphabetical order but + # the `default` and `classic` ones, which will be forced resp. in + # first and second position. + style_list = list(plt.style.available) # *new* list: avoids side effects. + style_list.remove('classic') # `classic` is in the list: first remove it. + style_list.sort() + style_list.insert(0, u'default') + style_list.insert(1, u'classic') + # Plot a demonstration figure for every available style sheet. - for style_label in plt.style.available: + for style_label in style_list: with plt.style.context(style_label): fig = plot_figure(style_label=style_label) From 25e1e745a74fd96e95906130572eee77cc484ca0 Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Mon, 17 Oct 2016 00:44:09 +0200 Subject: [PATCH 12/13] Fix default value of the named parameter in --- examples/style_sheets/style_sheets_reference.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index b8c6fd41ec72..0d7b5db625ca 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -98,14 +98,9 @@ def plot_histograms(ax, prng, nb_samples=10000): return ax -def plot_figure(style_label=None): +def plot_figure(style_label=""): """Setup and plot the demonstration figure with a given style. - - If `style_label` is None, fall back to the `default` style. """ - if style_label is None: - style_label = 'default' - # Use a dedicated RandomState instance to draw the same "random" values # across the different figures. prng = np.random.RandomState(96917002) From 09e1f3a4b9b22343f0d0f85db1e9fc2a34969809 Mon Sep 17 00:00:00 2001 From: Adrien F Vincent Date: Wed, 19 Oct 2016 00:00:13 +0200 Subject: [PATCH 13/13] Fix a typo in the example docstring --- examples/style_sheets/style_sheets_reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/style_sheets/style_sheets_reference.py b/examples/style_sheets/style_sheets_reference.py index 0d7b5db625ca..ef12c1ac3a09 100644 --- a/examples/style_sheets/style_sheets_reference.py +++ b/examples/style_sheets/style_sheets_reference.py @@ -3,7 +3,7 @@ Style sheets reference ====================== -This scripts demonstrates the different available style sheets on a +This script demonstrates the different available style sheets on a common set of example plots: scatter plot, image, bar graph, patches, line plot and histogram, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy