using CairoMakie
CairoMakie.activate!(type = "png")4 Plotting & Maps
4.1 Basic Plotting with CairoMakie
CairoMakie is a powerful plotting package that produces high-quality vector graphics and supports direct PDF output.
x = 0:0.1:2π
y = sin.(x)
fig = lines(x, y, axis=(xlabel="x", ylabel="y", title="Sine Wave"),
label="sin(x)", linewidth=2)
fig4.1.1 Multiple Series
fig = Figure()
ax = Axis(fig[1, 1], xlabel="x", ylabel="y")
lines!(ax, x, sin.(x), label="sin(x)", linewidth=2)
lines!(ax, x, cos.(x), label="cos(x)", linewidth=2, linestyle=:dash)
axislegend(ax)
fig4.1.2 Scatter Plots
xs = randn(50)
ys = randn(50)
fig = scatter(xs, ys,
axis=(xlabel="X", ylabel="Y", title="Random Points"),
markersize=12, alpha=0.7)
fig4.1.3 Heatmaps
z = [sin(xi) * cos(yi) for xi in 0:0.1:2π, yi in 0:0.1:2π]
fig = heatmap(z, axis=(xlabel="X", ylabel="Y", title="2D Function"),
colormap=:viridis)
fig4.2 Subplots
fig = Figure(size=(700, 500))
ax1 = Axis(fig[1, 1], title="Sine")
lines!(ax1, x, sin.(x))
ax2 = Axis(fig[1, 2], title="Cosine")
lines!(ax2, x, cos.(x))
ax3 = Axis(fig[2, 1], title="Tangent", limits=(nothing, (-5, 5)))
lines!(ax3, x, tan.(x))
ax4 = Axis(fig[2, 2], title="Random")
scatter!(ax4, randn(20), randn(20))
fig4.3 Contour Plots
x_cont = -2:0.1:2
y_cont = -2:0.1:2
z_cont = [exp(-(xi^2 + yi^2)) for xi in x_cont, yi in y_cont]
fig = Figure()
ax = Axis(fig[1, 1], xlabel="X", ylabel="Y", title="Gaussian")
co = contourf!(ax, x_cont, y_cont, z_cont, levels=10)
Colorbar(fig[1, 2], co)
fig4.4 Geographic Maps
NoteUnder Construction
Geographic mapping examples with GeoMakie.jl will be added soon.
4.4.1 Coordinate Systems
# Example with projected coordinates
using CoordinateTransformations
using Proj4
# Transform from WGS84 to UTM
wgs84 = Proj4.Projection("+proj=longlat +datum=WGS84")
utm35 = Proj4.Projection("+proj=utm +zone=35 +datum=WGS84")4.4.2 Plotting Geophysical Data
# Gravity anomaly map example
using CairoMakie
# Create synthetic gravity data
nx, ny = 50, 50
x_grav = range(0, 10, length=nx)
y_grav = range(0, 10, length=ny)
gz = [10 * exp(-((xi-5)^2 + (yi-5)^2)/2) for xi in x_grav, yi in y_grav]
fig = Figure()
ax = Axis(fig[1, 1],
xlabel="Easting (km)",
ylabel="Northing (km)",
title="Bouguer Gravity Anomaly")
hm = heatmap!(ax, x_grav, y_grav, gz, colormap=:RdBu)
Colorbar(fig[1, 2], hm, label="mGal")
fig