Repository navigation
Expand file tree
/
Copy path01_lines.qmd
More file actions
228 lines (163 loc) · 7.49 KB
/
Copy path01_lines.qmd
File metadata and controls
228 lines (163 loc) · 7.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# Line plots
<style>
.card {
transition: transform 0.2s ease, box-shadow 0.2s ease;
cursor: pointer;
border: 1px solid rgba(0,0,0,.125);
height: 100%;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 16px rgba(0,0,0,0.2);
}
.card-img-top {
width: 100%;
height: auto;
object-fit: cover;
}
</style>
<div class="grid">
<div class="g-col-6 g-col-md-4 g-col-lg-3">
<div class="card h-100">
<a href="01_lines.html#hello-world"><img src="lines_hello_thumb.png" class="card-img-top"></a>
<div class="card-body"><a href="01_lines.html#hello-world" class="card-title"><strong>Hello World</strong></a></div>
</div>
</div>
<div class="g-col-6 g-col-md-4 g-col-lg-3">
<div class="card h-100">
<a href="01_lines.html#cpt-colors"><img src="lines_cpt_thumb.png" class="card-img-top"></a>
<div class="card-body"><a href="01_lines.html#cpt-colors" class="card-title"><strong>CPT Colors</strong></a></div>
</div>
</div>
<div class="g-col-6 g-col-md-4 g-col-lg-3">
<div class="card h-100">
<a href="01_lines.html#line-colors-with-the-automatic-color-scheme"><img src="lines_auto_thumb.png" class="card-img-top"></a>
<div class="card-body"><a href="01_lines.html#line-colors-with-the-automatic-color-scheme" class="card-title"><strong>Auto Colors</strong></a></div>
</div>
</div>
<div class="g-col-6 g-col-md-4 g-col-lg-3">
<div class="card h-100">
<a href="01_lines.html#line-colors-with-user-set-color-scheme"><img src="lines_user_thumb.png" class="card-img-top"></a>
<div class="card-body"><a href="01_lines.html#line-colors-with-user-set-color-scheme" class="card-title"><strong>User Colors</strong></a></div>
</div>
</div>
<div class="g-col-6 g-col-md-4 g-col-lg-3">
<div class="card h-100">
<a href="01_lines.html#bezier-curve"><img src="lines_bezier_thumb.png" class="card-img-top"></a>
<div class="card-body"><a href="01_lines.html#bezier-curve" class="card-title"><strong>Bezier Curve</strong></a></div>
</div>
</div>
<div class="g-col-6 g-col-md-4 g-col-lg-3">
<div class="card h-100">
<a href="01_lines.html#decorated-line"><img src="lines_decorated_thumb.png" class="card-img-top"></a>
<div class="card-body"><a href="01_lines.html#decorated-line" class="card-title"><strong>Decorated Line</strong></a></div>
</div>
</div>
<div class="g-col-6 g-col-md-4 g-col-lg-3">
<div class="card h-100">
<a href="01_lines.html#text-decorated-line"><img src="lines_text_thumb.png" class="card-img-top"></a>
<div class="card-body"><a href="01_lines.html#text-decorated-line" class="card-title"><strong>Text Decorated</strong></a></div>
</div>
</div>
<div class="g-col-6 g-col-md-4 g-col-lg-3">
<div class="card h-100">
<a href="01_lines.html#the-snake-skier"><img src="lines_snake_thumb.png" class="card-img-top"></a>
<div class="card-body"><a href="01_lines.html#the-snake-skier" class="card-title"><strong>Snake Skier</strong></a></div>
</div>
</div>
<div class="g-col-6 g-col-md-4 g-col-lg-3">
<div class="card h-100">
<a href="01_lines.html#variable-sizedcolors-points"><img src="lines_variable_thumb.png" class="card-img-top"></a>
<div class="card-body"><a href="01_lines.html#variable-sizedcolors-points" class="card-title"><strong>Variable Points</strong></a></div>
</div>
</div>
</div>
## Hello world
```{julia}
using GMT
plot(1:10, rand(10), lw=1, lc=:blue, marker=:square,
markeredgecolor=0, size=0.2, markerfacecolor=:red, title="Hello World",
xlabel="Spoons", ylabel="Forks", show=true)
```
## CPT Colors
In this example the lines color is set using a custom CPT. Pen thickness is assigned automatically.
The custom CPT is used by setting the plot command’s cmap argument to ``true``. This workas because we previously computed the CPT and it will remain in memory until it's consumed when we finish the plot. The **level** argument sets the color to be used from the custom CPT.
In fact, in this case with a CPT already in memory, the **level** option alone would have triggered the line coloring and the **cmap** option could have been droped.
Normally we don't need to start a figure with a call to *basemap* because the *plot* function takes care of guessing reasonable defaults, but in this case we start with a curve with small amplitude and we grow the figure by adding more lines. So if we leave it to automatic guessing one would have to start by the largest amplitude curve.
```{julia}
using GMT
C = makecpt(range=(0,10,1));
basemap(region=(20,30,-10,10), figsize=(12,8))
x = 20:0.1:30;
for amp = 0:10
yy = amp .* sin.(x)
plot!(x, yy, cmap=true, level=(data=amp, nofill=true))
end
colorbar!(show=true)
```
## Line colors with the automatic color scheme
Here we are showing how to plot several lines at once and color them according to a circular color scheme comprised of 7 distinct colors. We start by generating a dummy matrix 8x5, where rows represent the vertex and the columns hold the lines. To tell the program that first column contains the coordinates and the remaining are all lines to be plotted we use the option **multicol**=*true*
```{julia}
using GMT
mat = GMT.fakedata(8, 5);
lines(mat, multicol=true, show=true)
```
## Line colors with user set color scheme
But if we want choose the colors ourselves, it is also easy though we need to go a bit lower in the data preparation.
The basic data type to transfer tabular data to GMT is the *GMTdataset* and the above command has converted the matrix into a *GMTdataset* under the hood but now we need to create one ourselves and fine control more details, like the colors and line thickness of the individual lines. Not that we have 5 lines but will provide 3 colors and 3 lines thicknesses. When we do this those properties are wrapped modulo its number.
```{julia}
using GMT
mat = GMT.fakedata(8, 5);
D = mat2ds(mat, color=["brown", "green", "blue"], linethick=[2, 1.0, 0.5, 0.25], multi=true);
# And now we just call *lines* (but using *plot* would have been the same) with the **D** argument.
lines(D, figsize=(14, 9.5), show=true)
```
## Bezier curve
```{julia}
using GMT
x = [0, 1, 2, 3, 2]; y = [0, 1, 1, 0.5, 0.25];
lines(x,y, limits=(-1,4,-0.5,2.0), scale=3.0, lw=1, markerfacecolor=:red,
size=0.5, bezier=true, title="Bezier curve", show=true)
```
## Decorated line
```{julia}
using GMT
xy = sind.(0:180) .+ 4.5
lines(xy, limits=(-5,185,4,6), figsize=(16,8), pen=(1,:red),
decorated=(dist=(2.5,0.25), symbol=:star, size=1,
pen=(0.5,:green), fill=:blue, dec2=true),
title=:Decorated, show=true)
```
## Text decorated line
```{julia}
using GMT
# Create a log spiral
t = linspace(0,2pi,100);
x = cos.(t) .* t; y = sin.(t) .* t;
txt = " In Vino Veritas - In Aqua, Rãs & Toads"
lines(x,y, region=(-4,7,-5.5,2.5), lw=2, lc=:sienna,
decorated=(quoted=true, const_label=txt, font=(25,"Times-Italic"),
curved=true, pen=(0.5,:red)),
aspect=:equal, show=true)
```
## The snake skier
Plot a skier on a sinusoid.
```{julia}
using GMT
x = GMT.linspace(0, 2pi); y = cos.(2x)*0.9;
lines(x,y, # The data
limits=(0,6.5,-1,2.0), # Fig limits
pen=(lw=7,lc=:sienna, arrow=(len=2.2,shape=:arrow, fill=:darkgreen)), # The "Snake"
figsize=(16,12), # Fig size
title="Double Snake")
plot!(3.49, 0.97, # Coordinates where to plot symbol
custom_symbol=(name="ski_alpine", size=1.7), # The skier symbol
fill=:black, show=true) # Fill the symbol in black
```
## Variable sized/colors points
```{julia}
using GMT
xs = linspace(0,10,30);
ys = 0.5 .* sin.(xs);
scatter(xs, ys, zcolor=true, ms=linspace(2,15,30).*2.54/72, show=true)
```