1""" 2================================ 3Filled and unfilled-marker types 4================================ 5 6Reference for filled- and unfilled-marker types included with Matplotlib. 7""" 8from six import iteritems 9import numpy as np 10import matplotlib.pyplot as plt 11from matplotlib.lines import Line2D 12 13 14points = np.ones(3) # Draw 3 points for each line 15text_style = dict(horizontalalignment='right', verticalalignment='center', 16 fontsize=12, fontdict={'family': 'monospace'}) 17marker_style = dict(linestyle=':', color='cornflowerblue', markersize=10) 18 19 20def format_axes(ax): 21 ax.margins(0.2) 22 ax.set_axis_off() 23 24 25def nice_repr(text): 26 return repr(text).lstrip('u') 27 28 29def split_list(a_list): 30 i_half = len(a_list) // 2 31 return (a_list[:i_half], a_list[i_half:]) 32 33############################################################################### 34# Plot all un-filled markers 35 36fig, axes = plt.subplots(ncols=2) 37 38# Filter out filled markers and marker settings that do nothing. 39# We use iteritems from six to make sure that we get an iterator 40# in both python 2 and 3 41unfilled_markers = [m for m, func in iteritems(Line2D.markers) 42 if func != 'nothing' and m not in Line2D.filled_markers] 43# Reverse-sort for pretty. We use our own sort key which is essentially 44# a python3 compatible reimplementation of python2 sort. 45unfilled_markers = sorted(unfilled_markers, 46 key=lambda x: (str(type(x)), str(x)))[::-1] 47for ax, markers in zip(axes, split_list(unfilled_markers)): 48 for y, marker in enumerate(markers): 49 ax.text(-0.5, y, nice_repr(marker), **text_style) 50 ax.plot(y * points, marker=marker, **marker_style) 51 format_axes(ax) 52fig.suptitle('un-filled markers', fontsize=14) 53 54 55############################################################################### 56# Plot all filled markers. 57 58fig, axes = plt.subplots(ncols=2) 59for ax, markers in zip(axes, split_list(Line2D.filled_markers)): 60 for y, marker in enumerate(markers): 61 ax.text(-0.5, y, nice_repr(marker), **text_style) 62 ax.plot(y * points, marker=marker, **marker_style) 63 format_axes(ax) 64fig.suptitle('filled markers', fontsize=14) 65 66plt.show() 67