Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96bf747

Browse files
committed
Merge pull request #2788 from tonysyu/mep12-lines-and-markers-demo
MEP12: Clean-up line and marker demos
2 parents 9451468 + 0791365 commit 96bf747

File tree

7 files changed

+126
-85
lines changed

7 files changed

+126
-85
lines changed

doc/users/pyplot_tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ rectangular grid, use the :func:`~matplotlib.pyplot.axes` command,
175175
which allows you to specify the location as ``axes([left, bottom,
176176
width, height])`` where all values are in fractional (0 to 1)
177177
coordinates. See :ref:`pylab_examples-axes_demo` for an example of
178-
placing axes manually and :ref:`pylab_examples-line_styles` for an
178+
placing axes manually and :ref:`pylab_examples-subplots_demo` for an
179179
example with lots-o-subplots.
180180

181181

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Reference for line-styles included with Matplotlib.
3+
"""
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
7+
8+
color = 'cornflowerblue'
9+
points = np.ones(5) # Draw 5 points for each line
10+
text_style = dict(horizontalalignment='right', verticalalignment='center',
11+
fontsize=12, fontdict={'family': 'monospace'})
12+
13+
14+
def format_axes(ax):
15+
ax.margins(0.2)
16+
ax.set_axis_off()
17+
18+
19+
def nice_repr(text):
20+
return repr(text).lstrip('u')
21+
22+
23+
# Plot all line styles.
24+
f, ax = plt.subplots()
25+
26+
linestyles = ['-', '--', '-.', ':']
27+
for y, linestyle in enumerate(linestyles):
28+
ax.text(-0.5, y, nice_repr(linestyle), **text_style)
29+
ax.plot(y * points, linestyle=linestyle, color=color, linewidth=3)
30+
format_axes(ax)
31+
ax.set_title('line styles')
32+
33+
plt.show()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Reference for marker fill-styles 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(5) # Draw 3 points for each line
10+
text_style = dict(horizontalalignment='right', verticalalignment='center',
11+
fontsize=12, fontdict={'family': 'monospace'})
12+
marker_style = dict(color='cornflowerblue', linestyle=':', marker='o',
13+
markersize=15, markerfacecoloralt='gray')
14+
15+
16+
def format_axes(ax):
17+
ax.margins(0.2)
18+
ax.set_axis_off()
19+
20+
21+
def nice_repr(text):
22+
return repr(text).lstrip('u')
23+
24+
25+
fig, ax = plt.subplots()
26+
27+
# Plot all fill styles.
28+
for y, fill_style in enumerate(Line2D.fillStyles):
29+
ax.text(-0.5, y, nice_repr(fill_style), **text_style)
30+
ax.plot(y * points, fillstyle=fill_style, **marker_style)
31+
format_axes(ax)
32+
ax.set_title('fill style')
33+
34+
plt.show()
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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()

examples/pylab_examples/filledmarker_demo.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

examples/pylab_examples/line_styles.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/tests/backend_driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
'fill_demo.py',
5757
'fill_demo_features.py',
5858
'line_demo_dash_control.py',
59+
'line_styles_reference.py',
5960
'scatter_with_legend.py'
6061
]
6162

@@ -193,7 +194,6 @@
193194
'legend_demo3.py',
194195
'line_collection.py',
195196
'line_collection2.py',
196-
'line_styles.py',
197197
'log_bar.py',
198198
'log_demo.py',
199199
'log_test.py',

0 commit comments

Comments
 (0)