-
-
Notifications
You must be signed in to change notification settings - Fork 290
/
examples2d.jl
797 lines (687 loc) · 24.6 KB
/
examples2d.jl
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
@reference_test "Test heatmap + image overlap" begin
heatmap(RNG.rand(32, 32))
image!(map(x -> RGBAf(x, 0.5, 0.5, 0.8), RNG.rand(32, 32)))
current_figure()
end
@reference_test "Test RGB heatmaps" begin
fig = Figure()
heatmap(fig[1, 1], RNG.rand(RGBf, 32, 32))
heatmap(fig[1, 2], RNG.rand(RGBAf, 32, 32))
fig
end
@reference_test "heatmap_interpolation" begin
f = Figure(resolution = (800, 800))
data = RNG.rand(32, 32)
# the grayscale heatmap hides the problem that interpolation based on values
# in GLMakie looks different than interpolation based on colors in CairoMakie
heatmap(f[1, 1], data, interpolate = false, colormap = :grays)
heatmap(f[1, 2], data, interpolate = true, colormap = :grays)
data_big = RNG.rand(1000, 1000)
heatmap(f[2, 1], data_big, interpolate = false, colormap = :grays)
heatmap(f[2, 2], data_big, interpolate = true, colormap = :grays)
xs = (1:32) .^ 1.5
ys = (1:32) .^ 1.5
data = RNG.rand(32, 32)
heatmap(f[3, 1], xs, ys, data, interpolate = false, colormap = :grays)
f
end
@reference_test "poly and colormap" begin
# example by @Paulms from MakieOrg/Makie.jl#310
points = Point2f[[0.0, 0.0], [0.1, 0.0], [0.1, 0.1], [0.0, 0.1]]
colors = [0.0 ,0.0, 0.5, 0.0]
fig, ax, polyplot = poly(points, color=colors, colorrange=(0.0, 1.0))
points = Point2f[[0.1, 0.1], [0.2, 0.1], [0.2, 0.2], [0.1, 0.2]]
colors = [0.5,0.5,1.0,0.3]
poly!(ax, points, color=colors, colorrange=(0.0, 1.0))
fig
end
@reference_test "quiver" begin
x = range(-2, stop=2, length=21)
arrows(x, x, RNG.rand(21, 21), RNG.rand(21, 21), arrowsize=0.05)
end
@reference_test "Arrows on hemisphere" begin
s = Sphere(Point3f(0), 0.9f0)
fig, ax, meshplot = mesh(s, transparency=true, alpha=0.05)
pos = decompose(Point3f, s)
dirs = decompose_normals(s)
arrows!(ax, pos, dirs, arrowcolor=:red, arrowsize=0.1, linecolor=:red)
fig
end
@reference_test "image" begin
fig = Figure()
image(fig[1,1], Makie.logo(), axis = (; aspect = DataAspect()))
image(fig[1, 2], RNG.rand(100, 500), axis = (; aspect = DataAspect()))
fig
end
@reference_test "FEM polygon 2D" begin
coordinates = [
0.0 0.0;
0.5 0.0;
1.0 0.0;
0.0 0.5;
0.5 0.5;
1.0 0.5;
0.0 1.0;
0.5 1.0;
1.0 1.0;
]
connectivity = [
1 2 5;
1 4 5;
2 3 6;
2 5 6;
4 5 8;
4 7 8;
5 6 9;
5 8 9;
]
color = [0.0, 0.0, 0.0, 0.0, -0.375, 0.0, 0.0, 0.0, 0.0]
poly(coordinates, connectivity, color=color, strokecolor=(:black, 0.6), strokewidth=4)
end
@reference_test "FEM mesh 2D" begin
coordinates = [
0.0 0.0;
0.5 0.0;
1.0 0.0;
0.0 0.5;
0.5 0.5;
1.0 0.5;
0.0 1.0;
0.5 1.0;
1.0 1.0;
]
connectivity = [
1 2 5;
1 4 5;
2 3 6;
2 5 6;
4 5 8;
4 7 8;
5 6 9;
5 8 9;
]
color = [0.0, 0.0, 0.0, 0.0, -0.375, 0.0, 0.0, 0.0, 0.0]
fig, ax, meshplot = mesh(coordinates, connectivity, color=color, shading=false)
wireframe!(ax, meshplot[1], color=(:black, 0.6), linewidth=3)
fig
end
@reference_test "colored triangle" begin
mesh(
[(0.0, 0.0), (0.5, 1.0), (1.0, 0.0)], color=[:red, :green, :blue],
shading=false
)
end
@reference_test "colored triangle with poly" begin
poly(
[(0.0, 0.0), (0.5, 1.0), (1.0, 0.0)],
color=[:red, :green, :blue],
strokecolor=:black, strokewidth=2
)
end
@reference_test "scale_plot" begin
t = range(0, stop=1, length=500) # time steps
θ = (6π) .* t # angles
x = # x coords of spiral
y = # y coords of spiral
lines(t .* cos.(θ), t .* sin.(θ);
color=t, colormap=:algae, linewidth=8, axis = (; aspect = DataAspect()))
end
@reference_test "Polygons" begin
points = decompose(Point2f, Circle(Point2f(50), 50f0))
fig, ax, pol = poly(points, color=:gray, strokewidth=10, strokecolor=:red)
# Optimized forms
poly!(ax, [Circle(Point2f(50 + 300), 50f0)], color=:gray, strokewidth=10, strokecolor=:red)
poly!(ax, [Circle(Point2f(50 + i, 50 + i), 10f0) for i = 1:100:400], color=:red)
poly!(ax, [Rect2f(50 + i, 50 + i, 20, 20) for i = 1:100:400], strokewidth=2, strokecolor=:green)
linesegments!(ax,
[Point2f(50 + i, 50 + i) => Point2f(i + 70, i + 70) for i = 1:100:400], linewidth=8, color=:purple
)
fig
end
@reference_test "Text Annotation" begin
text(
". This is an annotation!",
position=(300, 200),
align=(:center, :center),
fontsize=60,
font="Blackchancery"
)
end
@reference_test "Text rotation" begin
fig = Figure()
ax = fig[1, 1] = Axis(fig)
pos = (500, 500)
posis = Point2f[]
for r in range(0, stop=2pi, length=20)
p = pos .+ (sin(r) * 100.0, cos(r) * 100)
push!(posis, p)
text!(ax, "test",
position=p,
fontsize=50,
rotation=1.5pi - r,
align=(:center, :center)
)
end
scatter!(ax, posis, markersize=10)
fig
end
@reference_test "Standard deviation band" begin
# Sample 100 Brownian motion path and plot the mean trajectory together
# with a ±1σ band (visualizing uncertainty as marginal standard deviation).
n, m = 100, 101
t = range(0, 1, length=m)
X = cumsum(RNG.randn(n, m), dims=2)
X = X .- X[:, 1]
μ = vec(mean(X, dims=1)) # mean
lines(t, μ) # plot mean line
σ = vec(std(X, dims=1)) # stddev
band!(t, μ + σ, μ - σ) # plot stddev band
current_figure()
end
@reference_test "Streamplot animation" begin
v(x::Point2{T}, t) where T = Point2{T}(one(T) * x[2] * t, 4 * x[1])
sf = Observable(Base.Fix2(v, 0e0))
title_str = Observable("t = 0.00")
sp = streamplot(sf, -2..2, -2..2;
linewidth=2, arrow_size=20, colormap=:magma, axis=(;title=title_str))
Record(sp, LinRange(0, 20, 5)) do i
sf[] = Base.Fix2(v, i)
title_str[] = "t = $(round(i; sigdigits=2))"
end
end
@reference_test "Line changing colour" begin
fig, ax, lineplot = lines(RNG.rand(10); linewidth=10)
N = 20
Record(fig, 1:N; framerate=20) do i
lineplot.color = RGBf(i / N, (N - i) / N, 0) # animate scene
end
end
let
struct FitzhughNagumo{T}
ϵ::T
s::T
γ::T
β::T
end
@reference_test "streamplot" begin
P = FitzhughNagumo(0.1, 0.0, 1.5, 0.8)
ff(x, P::FitzhughNagumo) = Point2f(
(x[1] - x[2] - x[1]^3 + P.s) / P.ϵ,
P.γ * x[1] - x[2] + P.β
)
ff(x) = ff(x, P)
streamplot(ff, -1.5..1.5, -1.5..1.5, colormap=:magma)
end
end
@reference_test "Transforming lines" begin
N = 7 # number of colours in default palette
fig = Figure()
ax = Axis(fig)
fig[1,1] = ax
st = Stepper(fig)
xs = 0:9 # data
ys = zeros(10)
colors = Makie.default_palettes.color[]
plots = map(1:N) do i # plot lines
lines!(ax,
xs, ys;
color=colors[i],
linewidth=5
) # plot lines with colors
end
Makie.step!(st)
for (i, rot) in enumerate(LinRange(0, π / 2, N))
Makie.rotate!(plots[i], rot)
arc!(ax,
Point2f(0),
(8 - i),
pi / 2,
(pi / 2 - rot);
color=plots[i].color,
linewidth=5,
linestyle=:dash
)
end
Makie.step!(st)
st
end
@reference_test "Label rotations" begin
N = 18 # number of rotations
fig, ax, _ = scatter(0:1; axis = (; xlabel = "a nice and long x label for this axis", ylabel = "a nice and long y label for this axis"))
st = Stepper(fig)
#=
record(fig, "rot.gif") do io
for rot in LinRange(0, 2π, N)
ax.xlabelrotation[] = rot
ax.ylabelrotation[] = rot
recordframe!(io)
end
end
=#
Makie.step!(st)
st
end
@reference_test "Errorbars x y low high" begin
x = 1:10
y = sin.(x)
fig, ax, scatterplot = scatter(x, y)
errorbars!(ax, x, y, RNG.rand(10) .+ 0.5, RNG.rand(10) .+ 0.5)
errorbars!(ax, x, y, RNG.rand(10) .+ 0.5, RNG.rand(10) .+ 0.5, color = :red, direction = :x)
fig
end
@reference_test "Rangebars x y low high" begin
vals = -1:0.1:1
lows = zeros(length(vals))
highs = LinRange(0.1, 0.4, length(vals))
fig, ax, rbars = rangebars(vals, lows, highs, color = :red)
rangebars!(ax, vals, lows, highs, color = LinRange(0, 1, length(vals)),
whiskerwidth = 3, direction = :x)
fig
end
@reference_test "Simple pie chart" begin
fig = Figure(resolution=(800, 800))
pie(fig[1, 1], 1:5, color=collect(1:5), axis=(;aspect=DataAspect()))
fig
end
@reference_test "Hollow pie chart" begin
pie(1:5, color=collect(1.0:5), radius=2, inner_radius=1, axis=(;aspect=DataAspect()))
end
@reference_test "Open pie chart" begin
pie(0.1:0.1:1.0, normalize=false, axis=(;aspect=DataAspect()))
end
@reference_test "intersecting polygon" begin
x = LinRange(0, 2pi, 100)
poly(Point2f.(zip(sin.(x), sin.(2x))), color = :white, strokecolor = :blue, strokewidth = 10)
end
@reference_test "Line Function" begin
x = range(0, stop=3pi)
fig, ax, lineplot = lines(x, sin.(x))
lines!(ax, x, cos.(x), color=:blue)
fig
end
@reference_test "Grouped bar" begin
x1 = ["a_right", "a_right", "a_right", "a_right"]
y1 = [2, 3, -3, -2]
grp_dodge1 = [2, 2, 1, 1]
grp_stack1 = [1, 2, 1, 2]
x2 = ["z_left", "z_left", "z_left", "z_left"]
y2 = [2, 3, -3, -2]
grp_dodge2 = [1, 2, 1, 2]
grp_stack2 = [1, 1, 2, 2]
perm = [1, 4, 2, 7, 5, 3, 8, 6]
x = [x1; x2][perm]
x = categorical(x, levels = ["z_left", "a_right"])
y = [y1; y2][perm]
grp_dodge = [grp_dodge1; grp_dodge2][perm]
grp_stack = [grp_stack1; grp_stack2][perm]
tbl = (; x = x, grp_dodge = grp_dodge, grp_stack = grp_stack, y = y)
fig = Figure()
ax = Axis(fig[1,1])
barplot!(ax, levelcode.(tbl.x), tbl.y, dodge = tbl.grp_dodge, stack = tbl.grp_stack, color = tbl.grp_stack)
ax.xticks = (1:2, ["z_left", "a_right"])
fig
end
@reference_test "space 2D" begin
# This should generate a regular grid with text in a circle in a box. All
# sizes and positions are scaled to be equal across all options.
fig = Figure(resolution = (700, 700))
ax = Axis(fig[1, 1], width = 600, height = 600)
spaces = (:data, :pixel, :relative, :clip)
xs = [
[0.1, 0.35, 0.6, 0.85],
[0.1, 0.35, 0.6, 0.85] * 600,
[0.1, 0.35, 0.6, 0.85],
2 .* [0.1, 0.35, 0.6, 0.85] .- 1
]
scales = (0.02, 12, 0.02, 0.04)
for (i, space) in enumerate(spaces)
for (j, mspace) in enumerate(spaces)
s = 1.5scales[i]
mesh!(
ax, Rect2f(xs[i][i] - 2s, xs[i][j] - 2s, 4s, 4s), space = space,
shading = false, color = :blue)
lines!(
ax, Rect2f(xs[i][i] - 2s, xs[i][j] - 2s, 4s, 4s),
space = space, linewidth = 2, color = :red)
scatter!(
ax, Point2f(xs[i][i], xs[i][j]), color = :orange, marker = Circle,
markersize = 5scales[j], space = space, markerspace = mspace)
text!(
ax, "$space\n$mspace", position = Point2f(xs[i][i], xs[i][j]),
fontsize = scales[j], space = space, markerspace = mspace,
align = (:center, :center), color = :black)
end
end
xlims!(ax, 0, 1)
ylims!(ax, 0, 1)
fig
end
@reference_test "space 2D autolimits" begin
# Same code as above, but without setting limits. This should look different.
# Compared to the test above:
# - (data -> x) column should be centered in x direction
# - (data -> x) column: meshes and lines should be stretched in x direction
# - (data -> not data) column: circles and text should keep aspect
# - (x -> data) row should have stretched circle and text ain x direction
# - (not data -> data) should keep aspect ratio for mesh and lines
# - (data -> x) should be slightly missaligned with (not data -> x)
fig = Figure(resolution = (700, 700))
ax = Axis(fig[1, 1], width = 600, height = 600)
spaces = (:data, :pixel, :relative, :clip)
xs = [
[0.1, 0.35, 0.6, 0.85],
[0.1, 0.35, 0.6, 0.85] * 600,
[0.1, 0.35, 0.6, 0.85],
2 .* [0.1, 0.35, 0.6, 0.85] .- 1
]
scales = (0.02, 12, 0.02, 0.04)
for (i, space) in enumerate(spaces)
for (j, mspace) in enumerate(spaces)
s = 1.5scales[i]
mesh!(
ax, Rect2f(xs[i][i] - 2s, xs[i][j] - 2s, 4s, 4s), space = space,
shading = false, color = :blue)
lines!(
ax, Rect2f(xs[i][i] - 2s, xs[i][j] - 2s, 4s, 4s),
space = space, linewidth = 2, color = :red)
scatter!(
ax, Point2f(xs[i][i], xs[i][j]), color = :orange, marker = Circle,
markersize = 5scales[j], space = space, markerspace = mspace)
text!(
ax, "$space\n$mspace", position = Point2f(xs[i][i], xs[i][j]),
fontsize = scales[j], space = space, markerspace = mspace,
align = (:center, :center), color = :black)
end
end
fig
end
@reference_test "Scatter & Text transformations" begin
# Check that transformations apply in `space = :data`
fig, ax, p = scatter(Point2f(100, 0.5), marker = 'a', markersize=50)
t = text!(Point2f(100, 0.5), text = "Test", fontsize = 50)
translate!(p, -100, 0, 0)
translate!(t, -100, 0, 0)
# Check that scale and rotate don't act on the marker for scatter (only the position)
p2 = scatter!(ax, Point2f(1, 0), marker= 'a', markersize = 50)
Makie.rotate!(p2, pi/4)
scale!(p2, 0.5, 0.5, 1)
# but do act on glyphs of text
t2 = text!(ax, 1, 0, text = "Test", fontsize = 50)
Makie.rotate!(t2, pi/4)
scale!(t2, 0.5, 0.5, 1)
xlims!(ax, -0.2, 0.5)
ylims!(ax, 0, 1)
fig
end
@reference_test "Array of Images Scatter" begin
img = Makie.logo()
scatter(1:2, 1:2, marker = [img, img], markersize=reverse(size(img) ./ 10), axis=(limits=(0.5, 2.5, 0.5, 2.5),))
end
@reference_test "Image Scatter different sizes" begin
img = Makie.logo()
img2 = load(Makie.assetpath("doge.png"))
images = [img, img2]
markersize = map(img-> Vec2f(reverse(size(img) ./ 10)), images)
scatter(1:2, 1:2, marker = images, markersize=markersize, axis=(limits=(0.5, 2.5, 0.5, 2.5),))
end
@reference_test "2D surface with explicit color" begin
surface(1:10, 1:10, ones(10, 10); color = [RGBf(x*y/100, 0, 0) for x in 1:10, y in 1:10], shading = false)
end
@reference_test "heatmap and image colormap interpolation" begin
f = Figure(resolution=(500, 500))
crange = LinRange(0, 255, 10)
len = length(crange)
img = zeros(Float32, len, len + 2)
img[:, 1] .= 255f0
for (i, v) in enumerate(crange)
ib = i + 1
img[2:end-1, ib] .= v
img[1, ib] = 255-v
img[end, ib] = 255-v
end
kw(p, interpolate) = (axis=(title="$(p)(interpolate=$(interpolate))", aspect=DataAspect()), interpolate=interpolate, colormap=[:white, :black])
for (i, p) in enumerate([heatmap, image])
for (j, interpolate) in enumerate([true, false])
ax, pl = p(f[i,j], img; kw(p, interpolate)...)
hidedecorations!(ax)
end
end
f
end
@reference_test "nonlinear colormap" begin
n = 100
categorical = [false, true]
scales = [exp, identity, log, log10]
fig = Figure(resolution = (500, 250))
ax = Axis(fig[1, 1])
for (i, cat) in enumerate(categorical)
for (j, scale) in enumerate(scales)
cg = if cat
cgrad(:viridis, 5; scale = scale, categorical=true)
else
cgrad(:viridis; scale = scale, categorical=nothing)
end
lines!(ax, Point2f.(LinRange(i+0.1, i+0.9, n), j); color = 1:n, colormap = cg, linewidth = 10)
end
end
ax.xticks[] = ((1:length(categorical)) .+ 0.5, ["categorical=false", "categorical=true"])
ax.yticks[] = ((1:length(scales)), string.(scales))
fig
end
@reference_test "colormap with specific values" begin
cmap = cgrad([:black,:white,:orange],[0,0.2,1])
fig = Figure(resolution=(400,200))
ax = Axis(fig[1,1])
x = range(0,1,length=50)
scatter!(fig[1,1],Point2.(x,fill(0.,50)),color=x,colormap=cmap)
hidedecorations!(ax)
Colorbar(fig[2,1],vertical=false,colormap=cmap)
fig
end
@reference_test "multi rect with poly" begin
# use thick strokewidth, so it will make tests fail if something is missing
poly([Rect2f(0, 0, 1, 1)], color=:green, strokewidth=100, strokecolor=:black)
end
@reference_test "minor grid & scales" begin
data = LinRange(0.01, 0.99, 200)
f = Figure(resolution = (800, 800))
for (i, scale) in enumerate([log10, log2, log, sqrt, Makie.logit, identity])
row, col = fldmod1(i, 2)
Axis(f[row, col], yscale = scale, title = string(scale),
yminorticksvisible = true, yminorgridvisible = true,
xminorticksvisible = true, xminorgridvisible = true,
yminortickwidth = 4.0, xminortickwidth = 4.0,
yminorgridwidth = 6.0, xminorgridwidth = 6.0,
yminorticks = IntervalsBetween(3))
lines!(data, color = :blue)
end
f
end
@reference_test "Tooltip" begin
fig, ax, p = scatter(Point2f(0,0))
xlims!(ax, -10, 10)
ylims!(ax, -5, 5)
tt = tooltip!(ax, Point2f(0), text = "left", placement = :left)
tt.backgroundcolor[] = :red
tooltip!(
ax, 0, 0, "above with \nnewline\nand offset",
placement = :above, textpadding = (8, 5, 3, 2), align = 0.8
)
tooltip!(ax, Point2f(0), "below", placement = :below, outline_color = :red, outline_linestyle = :dot)
tooltip!(
ax, 0, 0, text = "right", placement = :right, fontsize = 30,
outline_linewidth = 5, offset = 30, triangle_size = 15,
strokewidth = 2f0, strokecolor = :cyan
)
fig
end
@reference_test "tricontourf" begin
x = RNG.randn(50)
y = RNG.randn(50)
z = -sqrt.(x .^ 2 .+ y .^ 2) .+ 0.1 .* RNG.randn.()
f, ax, tr = tricontourf(x, y, z)
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
Colorbar(f[1, 2], tr)
f
end
@reference_test "tricontourf extendhigh extendlow" begin
x = RNG.randn(50)
y = RNG.randn(50)
z = -sqrt.(x .^ 2 .+ y .^ 2) .+ 0.1 .* RNG.randn.()
f, ax, tr = tricontourf(x, y, z, levels = -1.8:0.2:-0.4, extendhigh = :red, extendlow = :orange)
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
Colorbar(f[1, 2], tr)
f
end
@reference_test "tricontourf relative mode" begin
x = RNG.randn(50)
y = RNG.randn(50)
z = -sqrt.(x .^ 2 .+ y .^ 2) .+ 0.1 .* RNG.randn.()
f, ax, tr = tricontourf(x, y, z, mode = :relative, levels = 0.2:0.1:1, colormap = :batlow)
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black, colormap = :batlow)
Colorbar(f[1, 2], tr)
f
end
@reference_test "tricontourf manual vs delaunay" begin
n = 20
angles = range(0, 2pi, length = n+1)[1:end-1]
x = [cos.(angles); 2 .* cos.(angles .+ pi/n)]
y = [sin.(angles); 2 .* sin.(angles .+ pi/n)]
z = (x .- 0.5).^2 + (y .- 0.5).^2 .+ 0.5 .* RNG.randn.()
triangulation_inner = reduce(hcat, map(i -> [0, 1, n] .+ i, 1:n))
triangulation_outer = reduce(hcat, map(i -> [n-1, n, 0] .+ i, 1:n))
triangulation = hcat(triangulation_inner, triangulation_outer)
f, ax, _ = tricontourf(x, y, z, triangulation = triangulation,
axis = (; aspect = 1, title = "Manual triangulation"))
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
tricontourf(f[1, 2], x, y, z, triangulation = Makie.DelaunayTriangulation(),
axis = (; aspect = 1, title = "Delaunay triangulation"))
scatter!(x, y, color = z, strokewidth = 1, strokecolor = :black)
f
end
@reference_test "marker offset in data space" begin
f = Figure()
ax = Axis(f[1, 1]; xticks=0:1, yticks=0:10)
scatter!(ax, fill(0, 10), 0:9, marker=Rect, marker_offset=Vec2f(0,0), transform_marker=true, markerspace=:data, markersize=Vec2f.(1, LinRange(0.1, 1, 10)))
lines!(ax, Rect(0, 0, 1, 10), color=:red)
f
end
@reference_test "trimspine" begin
with_theme(Axis = (limits = (0.5, 5.5, 0.3, 3.4), spinewidth = 8, topspinevisible = false, rightspinevisible = false)) do
f = Figure(resolution = (800, 800))
for (i, ts) in enumerate([(true, true), (true, false), (false, true), (false, false)])
Label(f[0, i], string(ts), tellwidth = false)
Axis(f[1, i], xtrimspine = ts)
Axis(f[2, i], ytrimspine = ts)
Axis(f[3, i], xtrimspine = ts, xreversed = true)
Axis(f[4, i], ytrimspine = ts, yreversed = true)
end
for (i, l) in enumerate(["x", "y", "x reversed", "y reversed"])
Label(f[i, 5], l, tellheight = false)
end
f
end
end
@reference_test "hexbin bin int" begin
f = Figure(resolution = (800, 800))
x = RNG.rand(300)
y = RNG.rand(300)
for i in 2:5
ax = Axis(f[fldmod1(i-1, 2)...], title = "bins = $i", aspect = DataAspect())
hexbin!(ax, x, y, bins = i)
wireframe!(ax, Rect2f(Point2f.(x, y)), color = :red)
scatter!(ax, x, y, color = :red, markersize = 5)
end
f
end
@reference_test "hexbin bin tuple" begin
f = Figure(resolution = (800, 800))
x = RNG.rand(300)
y = RNG.rand(300)
for i in 2:5
ax = Axis(f[fldmod1(i-1, 2)...], title = "bins = (3, $i)", aspect = DataAspect())
hexbin!(ax, x, y, bins = (3, i))
wireframe!(ax, Rect2f(Point2f.(x, y)), color = :red)
scatter!(ax, x, y, color = :red, markersize = 5)
end
f
end
@reference_test "hexbin two cellsizes" begin
f = Figure(resolution = (800, 800))
x = RNG.rand(300)
y = RNG.rand(300)
for (i, cellsize) in enumerate([0.1, 0.15, 0.2, 0.25])
ax = Axis(f[fldmod1(i, 2)...], title = "cellsize = ($cellsize, $cellsize)", aspect = DataAspect())
hexbin!(ax, x, y, cellsize = (cellsize, cellsize))
wireframe!(ax, Rect2f(Point2f.(x, y)), color = :red)
scatter!(ax, x, y, color = :red, markersize = 5)
end
f
end
@reference_test "hexbin one cellsize" begin
f = Figure(resolution = (800, 800))
x = RNG.rand(300)
y = RNG.rand(300)
for (i, cellsize) in enumerate([0.1, 0.15, 0.2, 0.25])
ax = Axis(f[fldmod1(i, 2)...], title = "cellsize = $cellsize", aspect = DataAspect())
hexbin!(ax, x, y, cellsize = cellsize)
wireframe!(ax, Rect2f(Point2f.(x, y)), color = :red)
scatter!(ax, x, y, color = :red, markersize = 5)
end
f
end
@reference_test "hexbin threshold" begin
f = Figure(resolution = (800, 800))
x = RNG.randn(100000)
y = RNG.randn(100000)
for (i, threshold) in enumerate([1, 10, 100, 500])
ax = Axis(f[fldmod1(i, 2)...], title = "threshold = $threshold", aspect = DataAspect())
hexbin!(ax, x, y, cellsize = 0.4, threshold = threshold)
end
f
end
@reference_test "hexbin scale" begin
x = RNG.randn(100000)
y = RNG.randn(100000)
f = Figure()
hexbin(f[1, 1], x, y, bins = 40,
axis = (aspect = DataAspect(), title = "scale = identity"))
hexbin(f[1, 2], x, y, bins = 40, scale=log10,
axis = (aspect = DataAspect(), title = "scale = log10"))
f
end
# Scatter needs working highclip/lowclip first
# @reference_test "hexbin colorrange highclip lowclip" begin
# x = RNG.randn(100000)
# y = RNG.randn(100000)
# hexbin(x, y,
# bins = 40,
# axis = (aspect = DataAspect(),),
# colorrange = (10, 300),
# highclip = :red,
# lowclip = :pink,
# strokewidth = 1,
# strokecolor = :gray30
# )
# end
@reference_test "Latex labels after the fact" begin
f = Figure(fontsize = 50)
ax = Axis(f[1, 1])
ax.xticks = ([3, 6, 9], [L"x" , L"y" , L"z"])
ax.yticks = ([3, 6, 9], [L"x" , L"y" , L"z"])
f
end
@reference_test "Rich text" begin
f = Figure(fontsize = 30, resolution = (800, 600))
ax = Axis(f[1, 1],
limits = (1, 100, 0.001, 1),
xscale = log10,
yscale = log2,
title = rich("A ", rich("title", color = :red, font = :bold_italic)),
xlabel = rich("X", subscript("label", fontsize = 25)),
ylabel = rich("Y", superscript("label")),
)
Label(f[1, 2], rich("Hi", rich("Hi", offset = (0.2, 0.2), color = :blue)), tellheight = false)
Label(f[1, 3], rich("X", superscript("super"), subscript("sub")), tellheight = false)
f
end