diff --git a/doc/users/pyplot_tutorial.rst b/doc/users/pyplot_tutorial.rst index f8edfc5c51e8..ae8443e85c04 100644 --- a/doc/users/pyplot_tutorial.rst +++ b/doc/users/pyplot_tutorial.rst @@ -175,7 +175,7 @@ rectangular grid, use the :func:`~matplotlib.pyplot.axes` command, which allows you to specify the location as ``axes([left, bottom, width, height])`` where all values are in fractional (0 to 1) coordinates. See :ref:`pylab_examples-axes_demo` for an example of -placing axes manually and :ref:`pylab_examples-line_styles` for an +placing axes manually and :ref:`pylab_examples-subplots_demo` for an example with lots-o-subplots. diff --git a/examples/lines_bars_and_markers/line_styles_reference.py b/examples/lines_bars_and_markers/line_styles_reference.py new file mode 100644 index 000000000000..625d0a5afde0 --- /dev/null +++ b/examples/lines_bars_and_markers/line_styles_reference.py @@ -0,0 +1,33 @@ +""" +Reference for line-styles included with Matplotlib. +""" +import numpy as np +import matplotlib.pyplot as plt + + +color = 'cornflowerblue' +points = np.ones(5) # Draw 5 points for each line +text_style = dict(horizontalalignment='right', verticalalignment='center', + fontsize=12, fontdict={'family': 'monospace'}) + + +def format_axes(ax): + ax.margins(0.2) + ax.set_axis_off() + + +def nice_repr(text): + return repr(text).lstrip('u') + + +# Plot all line styles. +f, ax = plt.subplots() + +linestyles = ['-', '--', '-.', ':'] +for y, linestyle in enumerate(linestyles): + ax.text(-0.5, y, nice_repr(linestyle), **text_style) + ax.plot(y * points, linestyle=linestyle, color=color, linewidth=3) + format_axes(ax) + ax.set_title('line styles') + +plt.show() diff --git a/examples/lines_bars_and_markers/marker_fillstyle_reference.py b/examples/lines_bars_and_markers/marker_fillstyle_reference.py new file mode 100644 index 000000000000..e7b36e605519 --- /dev/null +++ b/examples/lines_bars_and_markers/marker_fillstyle_reference.py @@ -0,0 +1,34 @@ +""" +Reference for marker fill-styles included with Matplotlib. +""" +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.lines import Line2D + + +points = np.ones(5) # Draw 3 points for each line +text_style = dict(horizontalalignment='right', verticalalignment='center', + fontsize=12, fontdict={'family': 'monospace'}) +marker_style = dict(color='cornflowerblue', linestyle=':', marker='o', + markersize=15, markerfacecoloralt='gray') + + +def format_axes(ax): + ax.margins(0.2) + ax.set_axis_off() + + +def nice_repr(text): + return repr(text).lstrip('u') + + +fig, ax = plt.subplots() + +# Plot all fill styles. +for y, fill_style in enumerate(Line2D.fillStyles): + ax.text(-0.5, y, nice_repr(fill_style), **text_style) + ax.plot(y * points, fillstyle=fill_style, **marker_style) + format_axes(ax) + ax.set_title('fill style') + +plt.show() diff --git a/examples/lines_bars_and_markers/marker_reference.py b/examples/lines_bars_and_markers/marker_reference.py new file mode 100644 index 000000000000..81bd3977ae4e --- /dev/null +++ b/examples/lines_bars_and_markers/marker_reference.py @@ -0,0 +1,57 @@ +""" +Reference for filled- and unfilled-marker types included with Matplotlib. +""" +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.lines import Line2D + + +points = np.ones(3) # Draw 3 points for each line +text_style = dict(horizontalalignment='right', verticalalignment='center', + fontsize=12, fontdict={'family': 'monospace'}) +marker_style = dict(linestyle=':', color='cornflowerblue', markersize=10) + + +def format_axes(ax): + ax.margins(0.2) + ax.set_axis_off() + + +def nice_repr(text): + return repr(text).lstrip('u') + + +def split_list(a_list): + i_half = len(a_list) // 2 + return (a_list[:i_half], a_list[i_half:]) + + +# Plot all un-filled markers +# -------------------------- + +fig, axes = plt.subplots(ncols=2) + +# Filter out filled markers and marker settings that do nothing. +unfilled_markers = [m for m, func in Line2D.markers.iteritems() + if func != 'nothing' and m not in Line2D.filled_markers] +unfilled_markers = sorted(unfilled_markers)[::-1] # Reverse-sort for pretty +for ax, markers in zip(axes, split_list(unfilled_markers)): + for y, marker in enumerate(markers): + ax.text(-0.5, y, nice_repr(marker), **text_style) + ax.plot(y * points, marker=marker, **marker_style) + format_axes(ax) +fig.suptitle('un-filled markers', fontsize=14) + + +# Plot all filled markers. +# ------------------------ + +fig, axes = plt.subplots(ncols=2) +for ax, markers in zip(axes, split_list(Line2D.filled_markers)): + for y, marker in enumerate(markers): + ax.text(-0.5, y, nice_repr(marker), **text_style) + ax.plot(y * points, marker=marker, **marker_style) + format_axes(ax) +fig.suptitle('filled markers', fontsize=14) + +plt.show() diff --git a/examples/pylab_examples/filledmarker_demo.py b/examples/pylab_examples/filledmarker_demo.py deleted file mode 100644 index b4f001512ffb..000000000000 --- a/examples/pylab_examples/filledmarker_demo.py +++ /dev/null @@ -1,38 +0,0 @@ -import itertools - -import numpy as np -import matplotlib.lines as mlines -import matplotlib.pyplot as plt - -colors = itertools.cycle(['b', 'g', 'r', 'c', 'm', 'y', 'k']) -altcolor = 'lightgreen' - -plt.rcParams['text.usetex'] = False # otherwise, '^' will cause trouble - -y = np.arange(10) -for marker in mlines.Line2D.filled_markers: - f = plt.figure() - f.text(.5,.95, "marker = %r" % marker, ha='center') - for i,fs in enumerate(mlines.Line2D.fillStyles): - color = colors.next() - - ax = f.add_subplot(121) - ax.plot(2*(4-i)+y, c=color, - marker=marker, - markersize=20, - fillstyle=fs, - label=fs) - ax.legend(loc=2) - ax.set_title('fillstyle') - - ax = f.add_subplot(122) - ax.plot(2*(4-i)+y, c=color, - marker=marker, - markersize=20, - markerfacecoloralt=altcolor, - fillstyle=fs, - label=fs) - ax.legend(loc=2) - ax.set_title('fillstyle') - -plt.show() diff --git a/examples/pylab_examples/line_styles.py b/examples/pylab_examples/line_styles.py deleted file mode 100644 index fdde90ee41a3..000000000000 --- a/examples/pylab_examples/line_styles.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python -# This should probably be replaced with a demo that shows all -# line and marker types in a single panel, with labels. - -import matplotlib.pyplot as plt -from matplotlib.lines import Line2D -import numpy as np - -t = np.arange(0.0, 1.0, 0.1) -s = np.sin(2*np.pi*t) -linestyles = ['_', '-', '--', ':'] -markers = [] -for m in Line2D.markers: - try: - if len(m) == 1 and m != ' ': - markers.append(m) - except TypeError: - pass - -styles = markers + [ - r'$\lambda$', - r'$\bowtie$', - r'$\circlearrowleft$', - r'$\clubsuit$', - r'$\checkmark$'] - -colors = ('b', 'g', 'r', 'c', 'm', 'y', 'k') - -plt.figure(figsize=(8,8)) - -axisNum = 0 -for row in range(6): - for col in range(5): - axisNum += 1 - ax = plt.subplot(6, 5, axisNum) - color = colors[axisNum % len(colors)] - if axisNum < len(linestyles): - plt.plot(t, s, linestyles[axisNum], color=color, markersize=10) - else: - style = styles[(axisNum - len(linestyles)) % len(styles)] - plt.plot(t, s, linestyle='None', marker=style, color=color, markersize=10) - ax.set_yticklabels([]) - ax.set_xticklabels([]) - -plt.show() diff --git a/examples/tests/backend_driver.py b/examples/tests/backend_driver.py index 1256d47a1d2c..619481b67044 100755 --- a/examples/tests/backend_driver.py +++ b/examples/tests/backend_driver.py @@ -56,6 +56,7 @@ 'fill_demo.py', 'fill_demo_features.py', 'line_demo_dash_control.py', + 'line_styles_reference.py', 'scatter_with_legend.py' ] @@ -193,7 +194,6 @@ 'legend_demo3.py', 'line_collection.py', 'line_collection2.py', - 'line_styles.py', 'log_bar.py', 'log_demo.py', 'log_test.py',