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

Skip to content

Commit ca179a6

Browse files
jklymakMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #15372: Add example for drawstyle
1 parent c52c6c5 commit ca179a6

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

examples/lines_bars_and_markers/step_demo.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,35 @@
1818
y = np.sin(x / 2)
1919

2020
plt.step(x, y + 2, label='pre (default)')
21-
plt.plot(x, y + 2, 'C0o', alpha=0.5)
21+
plt.plot(x, y + 2, 'o--', color='grey', alpha=0.3)
2222

2323
plt.step(x, y + 1, where='mid', label='mid')
24-
plt.plot(x, y + 1, 'C1o', alpha=0.5)
24+
plt.plot(x, y + 1, 'o--', color='grey', alpha=0.3)
2525

2626
plt.step(x, y, where='post', label='post')
27-
plt.plot(x, y, 'C2o', alpha=0.5)
27+
plt.plot(x, y, 'o--', color='grey', alpha=0.3)
2828

29+
plt.grid(axis='x', color='0.95')
2930
plt.legend(title='Parameter where:')
31+
plt.title('plt.step(where=...)')
32+
plt.show()
33+
34+
#############################################################################
35+
# The same behavior can be achieved by using the ``drawstyle`` parameter of
36+
# `.pyplot.plot`.
37+
38+
plt.plot(x, y + 2, drawstyle='steps', label='steps (=steps-pre)')
39+
plt.plot(x, y + 2, 'o--', color='grey', alpha=0.3)
40+
41+
plt.plot(x, y + 1, drawstyle='steps-mid', label='steps-mid')
42+
plt.plot(x, y + 1, 'o--', color='grey', alpha=0.3)
43+
44+
plt.plot(x, y, drawstyle='steps-post', label='steps-post')
45+
plt.plot(x, y, 'o--', color='grey', alpha=0.3)
46+
47+
plt.grid(axis='x', color='0.95')
48+
plt.legend(title='Parameter drawstyle:')
49+
plt.title('plt.plot(drawstyle=...)')
3050
plt.show()
3151

3252
#############################################################################
@@ -42,3 +62,5 @@
4262
import matplotlib
4363
matplotlib.axes.Axes.step
4464
matplotlib.pyplot.step
65+
matplotlib.axes.Axes.plot
66+
matplotlib.pyplot.plot

lib/matplotlib/lines.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ def set_markevery(self, every):
574574
be 0.5 multiplied by the display-coordinate-diagonal-distance
575575
along the line.
576576
577+
For examples see
578+
:doc:`/gallery/lines_bars_and_markers/markevery_demo`.
579+
577580
Notes
578581
-----
579582
Setting the markevery property will only show markers at actual data
@@ -1079,6 +1082,7 @@ def set_drawstyle(self, drawstyle):
10791082
- 'steps' is equal to 'steps-pre' and is maintained for
10801083
backward-compatibility.
10811084
1085+
For examples see :doc:`/gallery/lines_bars_and_markers/step_demo`.
10821086
"""
10831087
if drawstyle is None:
10841088
drawstyle = 'default'
@@ -1171,6 +1175,8 @@ def set_linestyle(self, ls):
11711175
11721176
where ``onoffseq`` is an even length tuple of on and off ink
11731177
in points. See also :meth:`set_dashes`.
1178+
1179+
For examples see :doc:`/gallery/lines_bars_and_markers/linestyles`.
11741180
"""
11751181
if isinstance(ls, str):
11761182
ds, ls = self._split_drawstyle_linestyle(ls)
@@ -1325,7 +1331,7 @@ def set_dashes(self, seq):
13251331
self.set_linestyle((0, seq))
13261332

13271333
def update_from(self, other):
1328-
"""Copy properties from other to self."""
1334+
"""Copy properties from *other* to self."""
13291335
Artist.update_from(self, other)
13301336
self._linestyle = other._linestyle
13311337
self._linewidth = other._linewidth
@@ -1402,6 +1408,7 @@ def set_dash_capstyle(self, s):
14021408
Parameters
14031409
----------
14041410
s : {'butt', 'round', 'projecting'}
1411+
For examples see :doc:`/gallery/lines_bars_and_markers/joinstyle`.
14051412
"""
14061413
s = s.lower()
14071414
cbook._check_in_list(self.validCap, s=s)
@@ -1416,6 +1423,7 @@ def set_solid_capstyle(self, s):
14161423
Parameters
14171424
----------
14181425
s : {'butt', 'round', 'projecting'}
1426+
For examples see :doc:`/gallery/lines_bars_and_markers/joinstyle`.
14191427
"""
14201428
s = s.lower()
14211429
cbook._check_in_list(self.validCap, s=s)

0 commit comments

Comments
 (0)