10
10
from pygmt .helpers import GMTTempFile
11
11
12
12
13
+ @pytest .fixture (scope = "module" , name = "legend_spec" )
14
+ def fixture_legend_spec ():
15
+ """
16
+ A string contains a legend specification.
17
+ """
18
+ return """
19
+ G -0.1i
20
+ H 24 Times-Roman My Map Legend
21
+ D 0.2i 1p
22
+ N 2
23
+ V 0 1p
24
+ S 0.1i c 0.15i p300/12 0.25p 0.3i This circle is hachured
25
+ S 0.1i e 0.15i yellow 0.25p 0.3i This ellipse is yellow
26
+ S 0.1i w 0.15i green 0.25p 0.3i This wedge is green
27
+ S 0.1i f0.1i+l+t 0.25i blue 0.25p 0.3i This is a fault
28
+ S 0.1i - 0.15i - 0.25p,- 0.3i A dashed contour
29
+ S 0.1i v0.1i+a40+e 0.25i magenta 0.25p 0.3i This is a vector
30
+ S 0.1i i 0.15i cyan 0.25p 0.3i This triangle is boring
31
+ V 0 1p
32
+ D 0.2i 1p
33
+ N 1
34
+ G 0.05i
35
+ G 0.05i
36
+ G 0.05i
37
+ L 9 4 R Smith et al., @%5%J. Geophys. Res., 99@%%, 2000
38
+ G 0.1i
39
+ P
40
+ T Let us just try some simple text that can go on a few lines.
41
+ T There is no easy way to predetermine how many lines will be required,
42
+ T so we may have to adjust the box height to get the right size box.
43
+ """
44
+
45
+
13
46
@pytest .mark .mpl_image_compare
14
47
def test_legend_position ():
15
48
"""
16
- Test that plots a position with each of the four legend coordinate systems.
49
+ Test positioning the legend with different coordinate systems.
17
50
"""
18
-
19
51
fig = Figure ()
20
52
fig .basemap (region = [- 2 , 2 , - 2 , 2 ], frame = True )
21
53
positions = ["jTR+jTR" , "g0/1" , "n0.2/0.2" , "x4i/2i/2i" ]
@@ -30,22 +62,18 @@ def test_legend_default_position():
30
62
"""
31
63
Test using the default legend position.
32
64
"""
33
-
34
65
fig = Figure ()
35
-
36
66
fig .basemap (region = [- 1 , 1 , - 1 , 1 ], frame = True )
37
-
38
67
fig .plot (x = [0 ], y = [0 ], style = "p10p" , label = "Default" )
39
68
fig .legend ()
40
-
41
69
return fig
42
70
43
71
44
72
@pytest .mark .benchmark
45
73
@pytest .mark .mpl_image_compare
46
74
def test_legend_entries ():
47
75
"""
48
- Test different marker types/shapes .
76
+ Test legend using the automatically generated legend entries .
49
77
"""
50
78
fig = Figure ()
51
79
fig .basemap (projection = "x1i" , region = [0 , 7 , 3 , 7 ], frame = True )
@@ -59,45 +87,16 @@ def test_legend_entries():
59
87
fig .plot (data = "@Table_5_11.txt" , pen = "1.5p,gray" , label = "My lines" )
60
88
fig .plot (data = "@Table_5_11.txt" , style = "t0.15i" , fill = "orange" , label = "Oranges" )
61
89
fig .legend (position = "JTR+jTR" )
62
-
63
90
return fig
64
91
65
92
66
93
@pytest .mark .mpl_image_compare
67
- def test_legend_specfile ():
94
+ def test_legend_specfile (legend_spec ):
68
95
"""
69
- Test specfile functionality .
96
+ Test passing a legend specification file .
70
97
"""
71
-
72
- specfile_contents = """
73
- G -0.1i
74
- H 24 Times-Roman My Map Legend
75
- D 0.2i 1p
76
- N 2
77
- V 0 1p
78
- S 0.1i c 0.15i p300/12 0.25p 0.3i This circle is hachured
79
- S 0.1i e 0.15i yellow 0.25p 0.3i This ellipse is yellow
80
- S 0.1i w 0.15i green 0.25p 0.3i This wedge is green
81
- S 0.1i f0.1i+l+t 0.25i blue 0.25p 0.3i This is a fault
82
- S 0.1i - 0.15i - 0.25p,- 0.3i A dashed contour
83
- S 0.1i v0.1i+a40+e 0.25i magenta 0.25p 0.3i This is a vector
84
- S 0.1i i 0.15i cyan 0.25p 0.3i This triangle is boring
85
- V 0 1p
86
- D 0.2i 1p
87
- N 1
88
- G 0.05i
89
- G 0.05i
90
- G 0.05i
91
- L 9 4 R Smith et al., @%5%J. Geophys. Res., 99@%%, 2000
92
- G 0.1i
93
- P
94
- T Let us just try some simple text that can go on a few lines.
95
- T There is no easy way to predetermine how many lines will be required,
96
- T so we may have to adjust the box height to get the right size box.
97
- """
98
-
99
98
with GMTTempFile () as specfile :
100
- Path (specfile .name ).write_text (specfile_contents , encoding = "utf-8" )
99
+ Path (specfile .name ).write_text (legend_spec , encoding = "utf-8" )
101
100
fig = Figure ()
102
101
fig .basemap (projection = "x6i" , region = [0 , 1 , 0 , 1 ], frame = True )
103
102
fig .legend (specfile .name , position = "JTM+jCM+w5i" )
@@ -111,3 +110,6 @@ def test_legend_fails():
111
110
fig = Figure ()
112
111
with pytest .raises (GMTInvalidInput ):
113
112
fig .legend (spec = ["@Table_5_11.txt" ])
113
+
114
+ with pytest .raises (GMTInvalidInput ):
115
+ fig .legend (spec = [1 , 2 ])
0 commit comments