Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up examples #45

Merged
merged 3 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/src/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ const viteConfig = defineViteConfig({
text: 'Animations',
collapsed: true,
items: [
{ text: 'scatter size', link: '/examples/animations/scatter_size' },
{ text: 'gravities', link: '/examples/animations/gravities' },
{ text: 'rotating_with_time', link: '/examples/animations/rotating_with_time' },
{ text: 'scatter_and_line', link: '/examples/animations/scatter_and_line' },
{ text: 'scatter_size', link: '/examples/animations/scatter_size' },
{ text: 'travelling_solar_system', link: '/examples/animations/travelling_solar_system' },
],
},
],
Expand Down
9 changes: 6 additions & 3 deletions examples/2d/bars/stripped_bars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ Random.seed!(13)
directions = [Vec2f(1), Vec2f(1, -1), Vec2f(1, 0), Vec2f(0, 1),
[Vec2f(1), Vec2f(1, -1)], [Vec2f(1, 0), Vec2f(0, 1)]]
colors = [:white, :orange, (:green, 0.5), :yellow, (:blue, 0.85), :black]

## then defining the patches are defined by calling LinePattern
patternColors = [Makie.LinePattern(direction = hatch; width = 5, tilesize = (20, 20),
linecolor = colors[indx], background_color = colors[end-indx+1])
for (indx, hatch) in enumerate(directions)]
for (indx, hatch) in enumerate(directions)];

## We could start with normal barplots
fig, ax, pltobj = barplot(1:2, strokewidth = 2, color = ["grey", "orange"],
figure = (size = (1200, 800), fontsize = 32))
figure = (; size = (600, 400)))
## and then append new bars with the patterns defined above
for (idx, pattern) in enumerate(patternColors)
barplot!(ax, [idx + 2], [idx * (2rand() + 1)], color = pattern, strokewidth = 2)
end
## change x ticks at every bar
ax.xticks = (1:8, ["grey", "orange", "/", "\\", "-", "|", "x", "+"])
fig
save("stripped_bars.png", fig); # hide
6 changes: 4 additions & 2 deletions examples/2d/density/density.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# ## density plot

# ![](density.svg)

using CairoMakie, Distributions, Random
CairoMakie.activate!(type = "svg") #hide

Random.seed!(124)
colors = ["#FF410D", "#6EE2FF", "#F7C530", "#95CC5E", "#D0DFE6", "#F79D1E"]
μσpairs = [[2,0.5], [-1,2], [0.25,1], [1,0.1], [1, 0.05], [1.2,0.1]]

fig = Figure(size = (600,400))
fig = Figure(; size = (600,400))
ax = Axis(fig[1,1]; palette = (; patchcolor = tuple.(colors, 0.45)))
for (idx, μσ) in enumerate(μσpairs)
density!(rand(Normal(μσ...), 1000), strokewidth = 1.5,
Expand All @@ -17,5 +18,6 @@ for (idx, μσ) in enumerate(μσpairs)
label = "$(μσ[1]), $(μσ[2])")
end
axislegend(L"\mu,\quad\sigma"; position= :cb, titlesize= 22)
hidedecorations!(ax; grid = false);
hidedecorations!(ax; grid = false)
fig
save("density.svg", fig); # hide
2 changes: 1 addition & 1 deletion examples/2d/density/mtcars_density.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ categ = unique(byCat)
colors1 = categorical_colors(:Hiroshige, length(categ))
colors2 = categorical_colors(:gnuplot, length(categ))

fig = Figure(size = (600, 800))
fig = Figure(; size = (600, 800))
ax1 = Axis(fig[2, 1], xlabel = "MPG", ylabel = "density", xgridstyle = :dash,
ygridstyle = :dash, rightspinevisible = false, topspinevisible = false)
ax2 = Axis(fig[3, 1], xlabel = "MPG", ylabel = "density")
Expand Down
2 changes: 1 addition & 1 deletion examples/2d/histogram/bins_counts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CairoMakie.activate!(type = "svg") #hide
Random.seed!(13)
n = 3000
data = randn(n)
fig = Figure(size = (1200, 800), fonts = (; regular= "sans"), fontsize = 20)
fig = Figure(; size = (1200, 800), fonts = (; regular= "sans"), fontsize = 20)
ax1 = Axis(fig[1, 1]; xlabel = "value", ylabel = "samples")
ax2 = Axis(fig[1, 2]; xlabel = "value", ylabel = "counts")
ax3 = Axis(fig[2, 1]; xlabel = "value", ylabel = "counts")
Expand Down
4 changes: 2 additions & 2 deletions examples/2d/histogram/hist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Random.seed!(124)
cmap = resample_cmap(:linear_wcmr_100_45_c42_n256, 256;
alpha = rand(256))

fig = Figure(size = (600,400))
ax = Axis(fig[1,1]; )
fig = Figure(; size = (600,400))
ax = Axis(fig[1,1])
hist!(rand(Normal(2.6,0.4), 1000), normalization = :pdf, offset = -1,
color = :values, colormap = :plasma, direction = :x, fillto = -0.5)
hist!(rand(Normal(2.6,0.4), 1000), normalization = :pdf, offset = 1,
Expand Down
4 changes: 2 additions & 2 deletions examples/2d/histogram/hist_pdf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ CairoMakie.activate!(type = "svg") #hide
Random.seed!(13)
n = 3000
data = randn(n)
fig = Figure(size = (600, 400))
ax1 = Axis(fig[1, 1], xlabel = "value")
fig = Figure(; size = (600, 400))
ax1 = Axis(fig[1, 1]; xlabel = "value")
hist!(ax1, data; normalization = :pdf, color = (:green, 0.5), label = "hist & pdf")
density!(ax1, data; color = (:orange, 0.25), label = "density!", strokewidth = 1)
axislegend(ax1, position = :rt)
Expand Down
5 changes: 3 additions & 2 deletions examples/2d/histogram/hists_on_the_sides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CairoMakie.activate!(type = "svg") #hide
Random.seed!(123)
n = 200
x, y, color = randn(n) / 2, randn(n), randn(n)
fig = Figure(size=(600, 400))
fig = Figure(; size=(600, 400))
ax1 = Axis(fig[1, 1])
ax2 = Axis(fig[2, 1])
ax3 = Axis(fig[2, 2])
Expand All @@ -25,6 +25,7 @@ hidexdecorations!(ax1, ticks=false, grid=false)
colsize!(fig.layout, 1, Relative(2 / 3))
rowsize!(fig.layout, 1, Relative(1 / 3))
colgap!(fig.layout, 10)
rowgap!(fig.layout, 10);
rowgap!(fig.layout, 10)
fig

save("hists_on_the_sides.svg", fig); # hide
2 changes: 1 addition & 1 deletion examples/2d/histogram/normalizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ n = 3000
data = randn(n)
normf = [:none, :pdf, :density, :probability]
colors = Makie.wong_colors()
fig = Figure(size = (1200, 800), fonts = (; regular ="sans"), fontsize = 20)
fig = Figure(; size = (1200, 800), fonts = (; regular ="sans"), fontsize = 20)
axs = [Axis(fig[i, j], xlabel = i == 2 ? "value" : "") for i in 1:2 for j in 1:2]
[hist!(axs[i], data; normalization = normf[i], color = colors[i],
label = "$(normf[i])") for i in 1:4]
Expand Down
2 changes: 1 addition & 1 deletion examples/2d/histogram/parallel_image_hist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function image_histogram()
greens = vec(float.(Images.green.(img)))
blues = vec(float.(Images.blue.(img)))

fig = Figure(;size = (1200,400))
fig = Figure(; size = (1200,400))
ax1 = Axis(fig[1, 1], aspect = DataAspect())
ax2 = Axis(fig[1, 2])
for (i, col) = enumerate([:red, :green, :blue])
Expand Down
8 changes: 5 additions & 3 deletions examples/2d/lines/line_cmap.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## line with colormap

# ![](line_cmap.svg)

using CairoMakie, ColorSchemes
CairoMakie.activate!(type = "svg") #hide

Expand All @@ -11,6 +15,4 @@ axislegend(ax)
Colorbar(fig[1, 2], obj, label = "sin(x)")
colgap!(fig.layout, 5)
fig
save("line_cmap.svg", fig); # hide

# ![](line_cmap.svg)
save("line_cmap.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_cmaps.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## lines width colormaps

# ![](line_cmaps.svg)

using CairoMakie, ColorSchemes
CairoMakie.activate!(type = "svg") #hide

Expand All @@ -14,6 +18,4 @@ cbars = [Colorbar(fig[1, i+1], lineas[i], label = labels[i], labelsize = 22)
for i in 1:4]
colgap!(fig.layout, 5)
fig
save("line_cmaps.svg", fig); # hide

# ![](line_cmaps.svg)
save("line_cmaps.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_cmaps_a.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## lines with colormap and colorbars around

# ![](line_cmaps_a.svg)

using CairoMakie, ColorSchemes
CairoMakie.activate!(type = "svg") #hide

Expand Down Expand Up @@ -25,6 +29,4 @@ fig[3, 2] = cbar3
colgap!(fig.layout, 5)
rowgap!(fig.layout, 5)
fig
save("line_cmaps_a.svg", fig); # hide

# ![](line_cmaps_a.svg)
save("line_cmaps_a.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_colored.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## lines colored with discrete colors from colormap: Legend

# ![](line_colored.svg)

using CairoMakie, ColorSchemes
CairoMakie.activate!(type = "svg") #hide

Expand All @@ -22,6 +26,4 @@ ax = Axis(fig[1, 1], aspect = 1, xlabel = L"x", ylabel = L"x^{p}",
Legend(fig[1, 2], ax, L"p"; nbanks = 2)
colsize!(fig.layout, 1, Aspect(1, 1.0))
fig
save("line_colored.svg", fig); # hide

# ![](line_colored.svg)
save("line_colored.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_colored_cbar.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## lines colored with discrete colors from colormap: Colorbar

# ![](line_colored_cbar.svg)

using CairoMakie, ColorSchemes
CairoMakie.activate!(type = "svg") #hide
xs = 0:0.01:1
Expand All @@ -22,6 +26,4 @@ Colorbar(fig[1, 2], limits = (-10, 10), nsteps = psize, colormap = cmap,
label = L"p", ticksize = 20, width = 20, tickalign = 1)
colsize!(fig.layout, 1, Aspect(1, 1.0))
fig
save("line_colored_cbar.svg", fig); # hide

# ![](line_colored_cbar.svg)
save("line_colored_cbar.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_inset.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## Inset line plot

# ![](line_inset.svg)

using CairoMakie, Random
CairoMakie.activate!(type = "svg") #hide

Expand All @@ -20,6 +24,4 @@ ax2.yticks = [-0.05, 0, 0.05]
ax2.xticks = [-3, -2.5, -2]
translate!(ax2.scene, 0, 0, 10);

save("line_inset.svg", fig); # hide

# ![](line_inset.svg)
save("line_inset.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_inset_h.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## Inset heatmap

# ![](line_inset_h.svg)

using CairoMakie
CairoMakie.activate!(type = "svg") #hide

Expand Down Expand Up @@ -25,6 +29,4 @@ hidespines!(ax2)
ax2.yticks = [-10, 0, 10]
ax2.xticks = [-10, 0, 10]
fig
save("line_inset_h.svg", fig); # hide

# ![](line_inset_h.svg)
save("line_inset_h.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_latex.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## lines, latex fonts

# ![](line_latex.svg)

using CairoMakie
CairoMakie.activate!(type = "svg") #hide
x = 0:0.05:4π
Expand All @@ -12,6 +16,4 @@ ylims!(-0.6, 1.05)
xlims!(-0.5, 12)
axislegend(L"f(x)"; position = :rt, backgroundcolor = (:grey90, 0.25));

save("line_latex.svg", fig); # hide

# ![](line_latex.svg)
save("line_latex.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_latex_bessel.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## besselj lines with latex fonts

# ![](line_latex_bessel.svg)

using CairoMakie, LaTeXStrings, SpecialFunctions
CairoMakie.activate!(type = "svg") #hide

Expand All @@ -10,6 +14,4 @@ for ν in 0:6
lines!(ax, x, besselj.(ν, x), label = latexstring("J_{$(ν)}(x)"))
end
axislegend(; nbanks = 3, framecolor = (:grey, 0.5));
save("line_latex_bessel.svg", fig); # hide

# ![](line_latex_bessel.svg)
save("line_latex_bessel.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_latex_bessels.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## bessely width latex fonts

# ![](line_latex_bessels.svg)

using CairoMakie, LaTeXStrings, SpecialFunctions
CairoMakie.activate!(type = "svg") #hide

Expand All @@ -13,6 +17,4 @@ end
axislegend(; position = :rb, nbanks = 2, framecolor = (:grey, 0.5))
ylims!(-1.8, 0.7)
fig
save("line_latex_bessels.svg", fig); # hide

# ![](line_latex_bessels.svg)
save("line_latex_bessels.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_single.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## simple line

# ![](line_single.svg)

using CairoMakie
CairoMakie.activate!(type = "svg") #hide

Expand All @@ -10,6 +14,4 @@ lines(x, x .^ 2; color = :black, linewidth = 2, linestyle = :dashdot, label = L"
axislegend("legend", position = :lt)
limits!(0, 10, 0, 100)

save("line_single.svg", current_figure()); # hide

# ![](line_single.svg)
save("line_single.svg", current_figure()); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_time.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## Time ticks on x axis

# ![](line_time.svg)

using CairoMakie, TimeSeries, Dates
CairoMakie.activate!(type = "svg") #hide
## dummy data
Expand All @@ -15,6 +19,4 @@ ax.xticks = (slice_dates, tempo[slice_dates])
ax.xticklabelrotation = π / 4
ax.xticklabelalign = (:right, :center)
fig
save("line_time.svg", fig); # hide

# ![](line_time.svg)
save("line_time.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_twin_axis.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## twin axis

# ![](line_twin_axis.svg)

using CairoMakie
CairoMakie.activate!(type = "svg") #hide

Expand All @@ -11,6 +15,4 @@ lines!(ax1, 0 .. 10, x -> x; color = :black)
lines!(ax2, 0 .. 10, x -> exp(-x); color = :dodgerblue)
hidespines!(ax2, :l, :b, :t)
hidexdecorations!(ax2);
save("line_twin_axis.svg", fig); # hide

# ![](line_twin_axis.svg)
save("line_twin_axis.svg", fig); # hide
8 changes: 5 additions & 3 deletions examples/2d/lines/line_two.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ## two lines

# ![](line_two.svg)

using CairoMakie
CairoMakie.activate!(type = "svg") #hide

Expand All @@ -12,6 +16,4 @@ lines(x, sin.(x); color = "#56B4E9", linewidth = 2, label = L"sin",
lines!(x, cos.(x); color = :black, linestyle = :dash, label = L"cos")
limits!(-2π, 2π, -1, 1)
axislegend("Legend", position = :lb);
save("line_two.svg", current_figure()); # hide

# ![](line_two.svg)
save("line_two.svg", current_figure()); # hide
Loading