Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 03bc3c1

Browse filesBrowse files
authored
Merge pull request matplotlib#15372 from timhoffm/drawstyle
Add example for drawstyle
2 parents 130a327 + 04f3c5f commit 03bc3c1
Copy full SHA for 03bc3c1

File tree

Expand file treeCollapse file tree

2 files changed

+34
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+34
-4
lines changed

‎examples/lines_bars_and_markers/step_demo.py

Copy file name to clipboardExpand all lines: examples/lines_bars_and_markers/step_demo.py
+25-3Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/lines.py
+9-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.