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 bcc63a4

Browse filesBrowse files
committed
Split into two subplots
1 parent 236eb23 commit bcc63a4
Copy full SHA for bcc63a4

File tree

Expand file treeCollapse file tree

1 file changed

+26
-17
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+26
-17
lines changed

‎examples/lines_bars_and_markers/linestyles.py

Copy file name to clipboardExpand all lines: examples/lines_bars_and_markers/linestyles.py
+26-17Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
from collections import OrderedDict
2020
from matplotlib.transforms import blended_transform_factory
2121

22-
linestyles = [
22+
23+
linestyle_str = [
2324
('solid', ('solid')), # Same as (0, ()) or '-'
2425
('dotted', ('dotted')), # Same as (0, (1, 1)) or '.'
2526
('dashed', ('dashed')), # Same as '--'
26-
('dashdot', ('dashdot')), # Same as '-.'
27+
('dashdot', ('dashdot'))] # Same as '-.'
2728

29+
linestyle_tuple = [
2830
('loosely dotted', (0, (1, 10))),
2931
('densely dotted', (0, (1, 1))),
3032

@@ -38,24 +40,31 @@
3840
('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))),
3941
('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))]
4042

41-
# Reverse the list so that plots and linestyles are in same order.
42-
linestyles = OrderedDict(linestyles[::-1])
43-
X, Y = np.linspace(0, 100, 10), np.zeros(10)
4443

45-
fig, ax = plt.subplots(figsize=(10, 6))
46-
for i, (name, linestyle) in enumerate(linestyles.items()):
47-
ax.plot(X, Y+i, linestyle=linestyle, linewidth=1.5, color='black')
44+
def simple_plot(ax, linestyles):
45+
yticklabels = []
46+
for i, (name, linestyle) in enumerate(linestyles):
47+
ax.plot(X, Y+i, linestyle=linestyle, linewidth=1.5, color='black')
48+
yticklabels.append(name)
49+
50+
ax.set(xticks=[], ylim=(-0.5, len(linestyles)-0.5),
51+
yticks=np.arange(len(linestyles)), yticklabels=yticklabels)
4852

49-
ax.set(xticks=[], ylim=(-0.5, len(linestyles)-0.5),
50-
yticks=np.arange(len(linestyles)), yticklabels=linestyles.keys())
53+
# For each line style, add a text annotation with a small offset from
54+
# the reference point (0 in Axes coords, y tick value in Data coords).
55+
reference_transform = blended_transform_factory(ax.transAxes, ax.transData)
56+
for i, (name, linestyle) in enumerate(linestyles):
57+
ax.annotate(repr(linestyle), xy=(0.0, i), xycoords=reference_transform,
58+
xytext=(-6, -12), textcoords='offset points', color="blue",
59+
fontsize=8, ha="right", family="monospace")
60+
61+
62+
X, Y = np.linspace(0, 100, 10), np.zeros(10)
63+
fig, ax = plt.subplots(2, 1, gridspec_kw={'height_ratios': [1, 2]},
64+
figsize=(10, 6))
5165

52-
# For each line style, add a text annotation with a small offset from
53-
# the reference point (0 in Axes coords, y tick value in Data coords).
54-
reference_transform = blended_transform_factory(ax.transAxes, ax.transData)
55-
for i, (name, linestyle) in enumerate(linestyles.items()):
56-
ax.annotate(repr(linestyle), xy=(0.0, i), xycoords=reference_transform,
57-
xytext=(-6, -12), textcoords='offset points', color="blue",
58-
fontsize=8, ha="right", family="monospace")
66+
simple_plot(ax[0], linestyle_str[::-1])
67+
simple_plot(ax[1], linestyle_tuple[::-1])
5968

6069
plt.tight_layout()
6170
plt.show()

0 commit comments

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