3
3
Linestyles
4
4
==========
5
5
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 example, ``(0, (3, 10, 1, 15))`` means
10
- 3pt-line,10pt-space,1pt-line,15pt-space with no offset .
6
+ Simple linestyles can be defined using the strings " solid", " dotted", " dashed"
7
+ or " dashdot". More refined control can be achieved by providing a dash tuple
8
+ `` (offset, (on_off_seq))``. For example, ``(0, (3, 10, 1, 15))`` means
9
<
10000
code class="diff-text syntax-highlighted-line addition">+ (3pt line, 10pt space, 1pt line, 15pt space) with no offset. See also
10
+ `.Line2D.set_linestyle` .
11
11
12
12
*Note*: The dash style can also be configured via `.Line2D.set_dashes`
13
13
as shown in :doc:`/gallery/lines_bars_and_markers/line_demo_dash_control`
26
26
27
27
linestyle_tuple = [
28
28
('loosely dotted' , (0 , (1 , 10 ))),
29
+ ('dotted' , (0 , (1 , 1 ))),
29
30
('densely dotted' , (0 , (1 , 1 ))),
30
31
31
32
('loosely dashed' , (0 , (5 , 10 ))),
33
+ ('dashed' , (0 , (5 , 5 ))),
32
34
('densely dashed' , (0 , (5 , 1 ))),
33
35
34
36
('loosely dashdotted' , (0 , (3 , 10 , 1 , 10 ))),
37
+ ('dashdotted' , (0 , (3 , 5 , 1 , 5 ))),
35
38
('densely dashdotted' , (0 , (3 , 1 , 1 , 1 ))),
36
39
37
40
('dashdotdotted' , (0 , (3 , 5 , 1 , 5 , 1 , 5 ))),
38
41
('loosely dashdotdotted' , (0 , (3 , 10 , 1 , 10 , 1 , 10 ))),
39
42
('densely dashdotdotted' , (0 , (3 , 1 , 1 , 1 , 1 , 1 )))]
40
43
41
44
42
- def simple_plot (ax , linestyles ):
45
+ def plot_linestyles (ax , linestyles ):
46
+ X , Y = np .linspace (0 , 100 , 10 ), np .zeros (10 )
43
47
yticklabels = []
48
+
44
49
for i , (name , linestyle ) in enumerate (linestyles ):
45
50
ax .plot (X , Y + i , linestyle = linestyle , linewidth = 1.5 , color = 'black' )
46
51
yticklabels .append (name )
@@ -56,12 +61,12 @@ def simple_plot(ax, linestyles):
56
61
xytext = (- 6 , - 12 ), textcoords = 'offset points' , color = "blue" ,
57
62
fontsize = 8 , ha = "right" , family = "monospace" )
58
63
59
- X , Y = np .linspace (0 , 100 , 10 ), np .zeros (10 )
60
- fig , ax = plt .subplots (2 , 1 , gridspec_kw = {'height_ratios' : [1 , 2 ]},
61
- figsize = (10 , 6 ))
62
64
63
- simple_plot (ax [0 ], linestyle_str [::- 1 ])
64
- simple_plot (ax [1 ], linestyle_tuple [::- 1 ])
65
+ fig , (ax0 , ax1 ) = plt .subplots (2 , 1 , gridspec_kw = {'height_ratios' : [1 , 3 ]},
66
+ figsize = (10 , 8 ))
67
+
<
4C6F
td data-grid-cell-id="diff-041eebd43c7b2000464be5bac9713d4900eb40c4dfb173880c3c37ebf3317e98-64-68-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
68
+ plot_linestyles (ax0 , linestyle_str [::- 1 ])
69
+ plot_linestyles (ax1 , linestyle_tuple [::- 1 ])
65
70
66
71
plt .tight_layout ()
67
72
plt .show ()
0 commit comments