|
| 1 | +""" |
| 2 | +Reference for filled- and unfilled-marker types included with Matplotlib. |
| 3 | +""" |
| 4 | +import numpy as np |
| 5 | +import matplotlib.pyplot as plt |
| 6 | +from matplotlib.lines import Line2D |
| 7 | + |
| 8 | + |
| 9 | +points = np.ones(3) # Draw 3 points for each line |
| 10 | +text_style = dict(horizontalalignment='right', verticalalignment='center', |
| 11 | + fontsize=12, fontdict={'family': 'monospace'}) |
| 12 | +marker_style = dict(linestyle=':', color='cornflowerblue', markersize=10) |
| 13 | + |
| 14 | + |
| 15 | +def format_axes(ax): |
| 16 | + ax.margins(0.2) |
| 17 | + ax.set_axis_off() |
| 18 | + |
| 19 | + |
| 20 | +def nice_repr(text): |
| 21 | + return repr(text).lstrip('u') |
| 22 | + |
| 23 | + |
| 24 | +def split_list(a_list): |
| 25 | + i_half = len(a_list) // 2 |
| 26 | + return (a_list[:i_half], a_list[i_half:]) |
| 27 | + |
| 28 | + |
| 29 | +# Plot all un-filled markers |
| 30 | +# -------------------------- |
| 31 | + |
| 32 | +fig, axes = plt.subplots(ncols=2) |
| 33 | + |
| 34 | +# Filter out filled markers and marker settings that do nothing. |
| 35 | +unfilled_markers = [m for m, func in Line2D.markers.iteritems() |
| 36 | + if func != 'nothing' and m not in Line2D.filled_markers] |
| 37 | +unfilled_markers = sorted(unfilled_markers)[::-1] # Reverse-sort for pretty |
| 38 | +for ax, markers in zip(axes, split_list(unfilled_markers)): |
| 39 | + for y, marker in enumerate(markers): |
| 40 | + ax.text(-0.5, y, nice_repr(marker), **text_style) |
| 41 | + ax.plot(y * points, marker=marker, **marker_style) |
| 42 | + format_axes(ax) |
| 43 | +fig.suptitle('un-filled markers', fontsize=14) |
| 44 | + |
| 45 | + |
| 46 | +# Plot all filled markers. |
| 47 | +# ------------------------ |
| 48 | + |
| 49 | +fig, axes = plt.subplots(ncols=2) |
| 50 | +for ax, markers in zip(axes, split_list(Line2D.filled_markers)): |
| 51 | + for y, marker in enumerate(markers): |
| 52 | + ax.text(-0.5, y, nice_repr(marker), **text_style) |
| 53 | + ax.plot(y * points, marker=marker, **marker_style) |
| 54 | + format_axes(ax) |
| 55 | +fig.suptitle('filled markers', fontsize=14) |
| 56 | + |
| 57 | +plt.show() |
0 commit comments