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 2f59110

Browse filesBrowse files
committed
Made changes as recommended
1 parent 0faa126 commit 2f59110
Copy full SHA for 2f59110

File tree

Expand file treeCollapse file tree

1 file changed

+20
-24
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-24
lines changed

‎examples/lines_bars_and_markers/linestyles.py

Copy file name to clipboardExpand all lines: examples/lines_bars_and_markers/linestyles.py
+20-24Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
Linestyles
44
==========
55
6-
This example showcases different linestyles copying those of Tikz/PGF.
7-
Linestyle can be provided as simple as *solid* , *dotted* or *dashed*.
8-
Moreover, the dashing of the line can be controlled by a dash tuple
9-
such as (offset, (on_off_seq)) as mentioned in `.Line2D.set_linestyle`.
10-
For e.g., ``(0, (3, 10, 1, 15))`` means 3pt-line,10pt-space,1pt-line,15pt-space
11-
with no offset.
6+
Linestyle can be provided as simple as *solid* , *dotted*, *dashed*
7+
or *dashdot*. Moreover, the dashing of the line can be controlled by
8+
a dash tuple such as (offset, (on_off_seq)) as mentioned in
9+
`.Line2D.set_linestyle`. For e.g., ``(0, (3, 10, 1, 15))`` means
10+
3pt-line,10pt-space,1pt-line,15pt-space with no offset.
1211
1312
*Note*: The dash style can also be configured via `.Line2D.set_dashes`
1413
as shown in :doc:`/gallery/lines_bars_and_markers/line_demo_dash_control`
@@ -21,37 +20,34 @@
2120
from matplotlib.transforms import blended_transform_factory
2221

2322
linestyles = [
24-
('solid', ('-')), # Same as (0, ())
25-
('dotted', (':')), # Same as (0, (1, 1))
26-
('dashed', ('--')),
27-
('dashdot', ('-.')),
23+
('solid', ('solid')), # Same as (0, ()) or '-'
24+
('dotted', ('dotted')), # Same as (0, (1, 1)) or '.'
25+
('dashed', ('dashed')), # Same as '--'
26+
('dashdot', ('dashdot')), # Same as '-.'
2827

29-
('loosely dotted', (0, (1, 10))),
30-
('densely dotted', (0, (1, 1))),
28+
('loosely dotted', (0, (1, 10))),
29+
('densely dotted', (0, (1, 1))),
3130

32-
('loosely dashed', (0, (5, 10))),
33-
('densely dashed', (0, (5, 1))),
31+
('loosely dashed', (0, (5, 10))),
32+
('densely dashed', (0, (5, 1))),
3433

35-
('loosely dashdotted', (0, (3, 10, 1, 10))),
36-
('densely dashdotted', (0, (3, 1, 1, 1))),
34+
('loosely dashdotted', (0, (3, 10, 1, 10))),
35+
('densely dashdotted', (0, (3, 1, 1, 1))),
3736

38-
('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))),
37+
('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))),
3938
('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))),
4039
('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))]
4140

4241
# Reverse the list so that plots and linestyles are in same order.
4342
linestyles = OrderedDict(linestyles[::-1])
44-
45-
plt.figure(figsize=(10, 6))
46-
ax = plt.subplot(1, 1, 1)
47-
4843
X, Y = np.linspace(0, 100, 10), np.zeros(10)
44+
45+
fig, ax = plt.subplots(figsize=(10, 6))
4946
for i, (name, linestyle) in enumerate(linestyles.items()):
5047
ax.plot(X, Y+i, linestyle=linestyle, linewidth=1.5, color='black')
5148

52-
ax.set_ylim(-0.5, len(linestyles)-0.5)
53-
plt.yticks(np.arange(len(linestyles)), linestyles.keys())
54-
plt.xticks([])
49+
ax.set(xticks=[], ylim=(-0.5, len(linestyles)-0.5),
50+
yticks=np.arange(len(linestyles)), yticklabels=linestyles.keys())
5551

5652
# For each line style, add a text annotation with a small offset from
5753
# the reference point (0 in Axes coords, y tick value in Data coords).

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.