diff --git a/docs/make.jl b/docs/make.jl index 1bbef3619..1fc906ad3 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -341,9 +341,6 @@ makedocs( ], ), sitename = "Makie Plotting Ecosystem", - expandfirst = [ - "plotting_functions.md", - ], pages = Any[ "Home" => "index.md", "Basics" => [ @@ -351,17 +348,36 @@ makedocs( "Layout Tutorial" => "makielayout/tutorial.md", "animation.md", "interaction.md", - "plotting_functions.md", + "Plotting Functions" => + joinpath.( + "plotting_functions", + filter( + endswith(".md"), + readdir(joinpath(srcpath, "plotting_functions"), + sort = true) + ) + ), "theming.md", ], "Documentation" => [ "plot_method_signatures.md", "Figure" => "figure.md", - "Axis" => "makielayout/laxis.md", - "GridLayout" => "makielayout/grids.md", - "Legend" => "makielayout/llegend.md", - "Layoutables & Widgets" => "makielayout/layoutables_examples.md", - "How Layouting Works" => "makielayout/layouting.md", + "Layoutables & Widgets" => [ + "makielayout/layoutables.md", + "makielayout/axis.md", + "makielayout/box.md", + "makielayout/button.md", + "makielayout/colorbar.md", + "makielayout/gridlayout.md", + "makielayout/label.md", + "makielayout/legend.md", + "makielayout/lscene.md", + "makielayout/menu.md", + "makielayout/slider.md", + "makielayout/toggle.md", + + ], + "makielayout/layouting.md", "generated/colors.md", "generated/plot-attributes.md", "recipes.md", diff --git a/docs/src/animation.md b/docs/src/animation.md index 74344989c..ff4fc38bb 100644 --- a/docs/src/animation.md +++ b/docs/src/animation.md @@ -19,6 +19,7 @@ As a start, here is how you can change the color of a line plot: ```@example 1 using GLMakie +GLMakie.activate!() # hide using AbstractPlotting.Colors figure, ax, lineplot = lines(0..10, sin; linewidth=10) diff --git a/docs/src/basic-tutorial.md b/docs/src/basic-tutorial.md index be3ee8729..eb0b3fb90 100644 --- a/docs/src/basic-tutorial.md +++ b/docs/src/basic-tutorial.md @@ -8,6 +8,7 @@ Otherwise, an interactive window will open when you return a `Figure`. ```@example 1 using GLMakie +GLMakie.activate!() # hide AbstractPlotting.inline!(true) nothing # hide ``` diff --git a/docs/src/figure.md b/docs/src/figure.md index 82a81f604..8f4eff460 100644 --- a/docs/src/figure.md +++ b/docs/src/figure.md @@ -56,9 +56,10 @@ If you index into the figure, a `FigurePosition` object that stores this indexin This object can be used to plot a new axis into a certain layout position in the figure, for example like this: ```@example -using GLMakie +using CairoMakie +CairoMakie.activate!() # hide -f = Figure() +f = Figure(resolution = (800, 600)) pos = f[1, 1] scatter(pos, rand(100, 2)) @@ -69,23 +70,33 @@ lines(pos2, cumsum(randn(100))) heatmap(f[1, 3], randn(10, 10)) f +save("figurepositions.svg", f); nothing # hide ``` +![figurepositions](figurepositions.svg) + You can also index further into a `FigurePosition`, which creates a `FigureSubposition`. With `FigureSubposition`s you can describe positions in arbitrarily nested grid layouts. Often, a desired plot layout can only be achieved with nesting, and repeatedly indexing makes this easy. ```@example -using GLMakie +using CairoMakie +CairoMakie.activate!() # hide + +f = Figure(resolution = (800, 600)) -f = Figure() f[1, 1] = Axis(f, title = "I'm not nested") f[1, 2][1, 1] = Axis(f, title = "I'm nested") + # plotting into nested positions also works heatmap(f[1, 2][2, 1], randn(20, 20)) + f +save("figurepositions_2.svg", f); nothing # hide ``` +![figurepositions_2](figurepositions_2.svg) + All nested grid layouts that don't exist yet, but are needed for a nested plotting call, are created in the background automatically. !!! note diff --git a/docs/src/index.md b/docs/src/index.md index 835bc2b92..ef32fad24 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -27,7 +27,6 @@ CairoMakie.activate!() - Learn the basics of plotting with Makie in the [Basic Tutorial](@ref) - Check out how to make more complex plots and layouts in the [Layout Tutorial](@ref) -- See examples of many plotting functions under [Plotting Functions](@ref). ```@eval using Markdown diff --git a/docs/src/interaction.md b/docs/src/interaction.md index 27489fa0b..f8165292c 100644 --- a/docs/src/interaction.md +++ b/docs/src/interaction.md @@ -221,7 +221,7 @@ end ## Interactive Widgets -Makie has a couple of useful interactive widgets like sliders, buttons and menus, which you can read about in the [Layoutables & Widgets](@ref) section. +Makie has a couple of useful interactive widgets like sliders, buttons and menus, which you can read about in the [Layoutables](@ref) section. ## Recording Animations with Interactions diff --git a/docs/src/lighting.md b/docs/src/lighting.md index 0763400c9..07ab29f31 100644 --- a/docs/src/lighting.md +++ b/docs/src/lighting.md @@ -37,6 +37,7 @@ A matcap (material capture) is a texture which is applied based on the normals o ```@example 1 using GLMakie +GLMakie.activate!() # hide using AbstractPlotting xs = -10:0.1:10 ys = -10:0.1:10 @@ -64,6 +65,7 @@ scene ```@example 1 using GLMakie +GLMakie.activate!() # hide GLMakie.enable_SSAO[] = true close(GLMakie.global_gl_screen()) # close any open screen @@ -86,7 +88,9 @@ scene ``` ```@example 1 -using FileIO, GLMakie +using FileIO +using GLMakie +GLMakie.activate!() # hide catmesh = FileIO.load(GLMakie.assetpath("cat.obj")) gold = FileIO.load(download("https://raw.githubusercontent.com/nidorx/matcaps/master/1024/E6BF3C_5A4719_977726_FCFC82.png")) diff --git a/docs/src/makielayout/laxis.md b/docs/src/makielayout/axis.md similarity index 99% rename from docs/src/makielayout/laxis.md rename to docs/src/makielayout/axis.md index 95aedd7ed..104c86acb 100755 --- a/docs/src/makielayout/laxis.md +++ b/docs/src/makielayout/axis.md @@ -3,6 +3,8 @@ using CairoMakie CairoMakie.activate!(type = "png") ``` +# Axis + ## Creating an Axis The `Axis` is a 2D axis that works well with automatic layouts. diff --git a/docs/src/makielayout/box.md b/docs/src/makielayout/box.md new file mode 100644 index 000000000..0133facee --- /dev/null +++ b/docs/src/makielayout/box.md @@ -0,0 +1,24 @@ +```@eval +using CairoMakie +CairoMakie.activate!() +``` + +# Box + +A simple rectangle poly that is layoutable. This can be useful to make boxes for +facet plots or when a rectangular placeholder is needed. + +```@example +using CairoMakie +using ColorSchemes + +fig = Figure(resolution = (1200, 900)) + +rects = fig[1:4, 1:6] = [ + Box(fig, color = c) + for c in get.(Ref(ColorSchemes.rainbow), (0:23) ./ 23)] + +save("example_lrect.svg", fig); nothing # hide +``` + +![example lrect](example_lrect.svg) \ No newline at end of file diff --git a/docs/src/makielayout/button.md b/docs/src/makielayout/button.md new file mode 100644 index 000000000..0151bdcc9 --- /dev/null +++ b/docs/src/makielayout/button.md @@ -0,0 +1,29 @@ +```@eval +using CairoMakie +CairoMakie.activate!() +``` + +# Button + +```@example +using CairoMakie + +fig = Figure(resolution = (1200, 900)) + +Axis(fig[1, 1]) +fig[2, 1] = buttongrid = GridLayout(tellwidth = false) + +buttons = buttongrid[1, 1:5] = [Button(fig, label = "Button $i") for i in 1:5] + +for button in buttons + on(button.clicks) do n + println("$(button.label[]) was clicked $n times.") + end +end + +fig + +save("example_lbutton.svg", fig); nothing # hide +``` + +![example lbutton](example_lbutton.svg) \ No newline at end of file diff --git a/docs/src/makielayout/colorbar.md b/docs/src/makielayout/colorbar.md new file mode 100644 index 000000000..efedcdb2c --- /dev/null +++ b/docs/src/makielayout/colorbar.md @@ -0,0 +1,76 @@ +```@eval +using CairoMakie +CairoMakie.activate!() +``` + +# Colorbar + +A Colorbar needs a colormap and a tuple of low/high limits. +The colormap's axis will then span from low to high along the visual representation of the colormap. +You can set ticks in a similar way to `Axis`. + +Here's how you can create Colorbars manually. + +```@example +using CairoMakie + +fig = Figure(resolution = (1200, 900)) + +Axis(fig[1, 1]) + +# vertical colorbars +Colorbar(fig[1, 2], width = 25, limits = (0, 10), colormap = :viridis, + flipaxis = false) +Colorbar(fig[1, 3], width = 25, limits = (0, 5), +colormap = cgrad(:Spectral, 5, categorical = true)) +Colorbar(fig[1, 4], width = 25, limits = (-1, 1), colormap = :heat, + highclip = :cyan, lowclip = :red, label = "Temperature") + +# horizontal colorbars +Colorbar(fig[2, 1], height = 25, limits = (0, 10), colormap = :viridis, + vertical = false) +Colorbar(fig[3, 1], height = 25, limits = (0, 5), + colormap = cgrad(:Spectral, 5, categorical = true), vertical = false) +Colorbar(fig[4, 1], height = 25, limits = (-1, 1), colormap = :heat, + label = "Temperature", vertical = false, flipaxis = false, + highclip = :cyan, lowclip = :red) + +fig + +save("example_colorbar.svg", fig); nothing # hide +``` + +![example colorbar](example_colorbar.svg) + +You can also automatically choose colormap and limits for certain plot objects by passing them as the second argument. + +```@example +using CairoMakie + +xs = LinRange(0, 20, 50) +ys = LinRange(0, 15, 50) +zs = [cos(x) * sin(y) for x in xs, y in ys] + +fig = Figure(resolution = (1200, 900)) + +ax, hm = heatmap(fig[1, 1][1, 1], xs, ys, zs) +Colorbar(fig[1, 1][1, 2], hm, width = 20) + +ax, hm = heatmap(fig[1, 2][1, 1], xs, ys, zs, colormap = :grays, + colorrange = (-0.75, 0.75), highclip = :red, lowclip = :blue) +Colorbar(fig[1, 2][1, 2], hm, width = 20) + +ax, hm = contourf(fig[2, 1][1, 1], xs, ys, zs, + levels = -1:0.25:1, colormap = :heat) +Colorbar(fig[2, 1][1, 2], hm, width = 20, ticks = -1:0.25:1) + +ax, hm = contourf(fig[2, 2][1, 1], xs, ys, zs, + colormap = :Spectral, levels = [-1, -0.5, -0.25, 0, 0.25, 0.5, 1]) +Colorbar(fig[2, 2][1, 2], hm, width = 20, ticks = -1:0.25:1) + +fig +save("example_colorbar_2.svg", fig); nothing # hide +``` + +![example colorbar 2](example_colorbar_2.svg) + diff --git a/docs/src/makielayout/grids.md b/docs/src/makielayout/gridlayout.md similarity index 99% rename from docs/src/makielayout/grids.md rename to docs/src/makielayout/gridlayout.md index 08becb8a7..8b38d6a70 100755 --- a/docs/src/makielayout/grids.md +++ b/docs/src/makielayout/gridlayout.md @@ -3,6 +3,8 @@ using CairoMakie CairoMakie.activate!() ``` +# GridLayout + ## Setting column and row sizes correctly There are four different types of sizes you can give rows and columns. diff --git a/docs/src/makielayout/label.md b/docs/src/makielayout/label.md new file mode 100644 index 000000000..6a72ff22b --- /dev/null +++ b/docs/src/makielayout/label.md @@ -0,0 +1,26 @@ +```@eval +using CairoMakie +CairoMakie.activate!() +``` + +# Label + +This is just normal text, except it's also layoutable. A text's size is known, +so rows and columns in a GridLayout can shrink to the appropriate width or height. + +```@example +using CairoMakie + +fig = Figure(resolution = (1200, 900)) + +fig[1:2, 1:3] = [Axis(fig) for _ in 1:6] + +supertitle = Label(fig[0, :], "Six plots", textsize = 30) + +sideinfo = Label(fig[2:3, 0], "This text is vertical", rotation = pi/2) + +save("example_ltext.svg", fig); nothing # hide +``` + +![example ltext](example_ltext.svg) + diff --git a/docs/src/makielayout/layoutables.md b/docs/src/makielayout/layoutables.md new file mode 100755 index 000000000..5dd6f6317 --- /dev/null +++ b/docs/src/makielayout/layoutables.md @@ -0,0 +1,79 @@ +# Layoutables + +!!! note + All examples in this section are presented as static CairoMakie vector graphics for clarity of visuals. + Keep in mind that CairoMakie is not interactive. + Use GLMakie for interactive widgets, as WGLMakie currently doesn't have picking implemented. + +Layoutables are objects which can be added to a Figure or Scene and have their location and size controlled by a `GridLayout`. +A `Figure` has its own internal `GridLayout` and therefore offers simplified syntax for adding layoutables to it. +If you want to work with a bare `Scene`, you can attach a `GridLayout` to its pixel area. +The `layoutscene` function is supplied for this purpose. + +!!! note + A layout only controls an object's position or bounding box. + A Layoutable can be controlled by the GridLayout of a Figure but not be added as a visual to the Figure. + A Layoutable can also be added to a Scene without being inside any GridLayout, if you specify the bounding box yourself. + +## Adding to a Figure + +Here's one way to add a Layoutable, in this case an `Axis`, to a Figure. + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +ax = Axis(f[1, 1]) +f +save("layoutables_figure.svg", f); nothing # hide +``` + +![layoutables_figure](layoutables_figure.svg) + +## Adding to a Scene + +And here's how you can add the same Layoutable to a Scene, which is the primitive object underlying a Figure. +As discussed above, `layoutscene` is an older convenience method to create a Scene with an attached GridLayout that tracks its size. +This is mostly not needed anymore since Figures were added. + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +scene, layout = layoutscene(resolution = (800, 600)) +ax = layout[1, 1] = Axis(scene) +scene +save("layoutables_scene.svg", scene); nothing # hide +``` + +![layoutables_scene](layoutables_scene.svg) + +## Specifying a boundingbox directly + +Sometimes you just want to place a Layoutable in a specific location, without it being controlled by a dynamic layout. +You can do this by setting the `bbox` parameter, which is usually controlled by the layout, manually. +The boundingbox should be a 2D `Rect`, and can also be an Observable if you plan to change it dynamically. +The function `BBox` creates an `FRect2D`, but instead of passing origin and widths, you pass left, right, bottom and top boundaries directly. + +Here's an example where two axes are placed manually: + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f, bbox = BBox(100, 300, 100, 500), title = "Axis 1") +Axis(f, bbox = BBox(400, 700, 200, 400), title = "Axis 2") +f +save("layoutables_manual_bbox.svg", f); nothing # hide +``` + +![layoutables_manual_bbox](layoutables_manual_bbox.svg) + +## Deleting Layoutables + +To remove layoutables from their layout and the figure or scene, use `delete!(layoutable)`. diff --git a/docs/src/makielayout/layoutables_examples.md b/docs/src/makielayout/layoutables_examples.md deleted file mode 100755 index 429848f6f..000000000 --- a/docs/src/makielayout/layoutables_examples.md +++ /dev/null @@ -1,320 +0,0 @@ -```@eval -using CairoMakie -CairoMakie.activate!() -``` - -# Layoutables & Widgets - -!!! note - All examples here are presented as CairoMakie svg's for clarity of visuals, but keep in mind that CairoMakie is not interactive. Use GLMakie for interactive widgets, WGLMakie currently doesn't have picking implemented which is needed for them. - -```@contents -Pages = ["layoutables_examples.md"] -Depth = 2 -``` - -## Colorbar - -A Colorbar needs a colormap and a tuple of low/high limits. -The colormap's axis will then span from low to high along the visual representation of the colormap. -You can set ticks in a similar way to `Axis`. - -Here's how you can create Colorbars manually. - -```@example -using CairoMakie - -fig = Figure(resolution = (1200, 900)) - -Axis(fig[1, 1]) - -# vertical colorbars -Colorbar(fig[1, 2], width = 25, limits = (0, 10), colormap = :viridis, - flipaxis = false) -Colorbar(fig[1, 3], width = 25, limits = (0, 5), -colormap = cgrad(:Spectral, 5, categorical = true)) -Colorbar(fig[1, 4], width = 25, limits = (-1, 1), colormap = :heat, - highclip = :cyan, lowclip = :red, label = "Temperature") - -# horizontal colorbars -Colorbar(fig[2, 1], height = 25, limits = (0, 10), colormap = :viridis, - vertical = false) -Colorbar(fig[3, 1], height = 25, limits = (0, 5), - colormap = cgrad(:Spectral, 5, categorical = true), vertical = false) -Colorbar(fig[4, 1], height = 25, limits = (-1, 1), colormap = :heat, - label = "Temperature", vertical = false, flipaxis = false, - highclip = :cyan, lowclip = :red) - -fig - -save("example_colorbar.svg", fig); nothing # hide -``` - -![example colorbar](example_colorbar.svg) - -You can also automatically choose colormap and limits for certain plot objects by passing them as the second argument. - -```@example -using CairoMakie - -xs = LinRange(0, 20, 50) -ys = LinRange(0, 15, 50) -zs = [cos(x) * sin(y) for x in xs, y in ys] - -fig = Figure(resolution = (1200, 900)) - -ax, hm = heatmap(fig[1, 1][1, 1], xs, ys, zs) -Colorbar(fig[1, 1][1, 2], hm, width = 20) - -ax, hm = heatmap(fig[1, 2][1, 1], xs, ys, zs, colormap = :grays, - colorrange = (-0.75, 0.75), highclip = :red, lowclip = :blue) -Colorbar(fig[1, 2][1, 2], hm, width = 20) - -ax, hm = contourf(fig[2, 1][1, 1], xs, ys, zs, - levels = -1:0.25:1, colormap = :heat) -Colorbar(fig[2, 1][1, 2], hm, width = 20, ticks = -1:0.25:1) - -ax, hm = contourf(fig[2, 2][1, 1], xs, ys, zs, - colormap = :Spectral, levels = [-1, -0.5, -0.25, 0, 0.25, 0.5, 1]) -Colorbar(fig[2, 2][1, 2], hm, width = 20, ticks = -1:0.25:1) - -fig -save("example_colorbar_2.svg", fig); nothing # hide -``` - -![example colorbar 2](example_colorbar_2.svg) - -## Slider - -A simple slider without a label. You can create a label using a `Label` object, -for example. You need to specify a range that constrains the slider's possible values. -You can then lift the `value` observable to make interactive plots. - -```@example -using CairoMakie - -fig = Figure(resolution = (1200, 900)) - -Axis(fig[1, 1]) -sl1 = Slider(fig[2, 1], range = 0:0.01:10, startvalue = 3) -sl2 = Slider(fig[3, 1], range = 0:0.01:10, startvalue = 5) -sl3 = Slider(fig[4, 1], range = 0:0.01:10, startvalue = 7) - -sl4 = Slider(fig[:, 2], range = 0:0.01:10, horizontal = false, - tellwidth = true, height = nothing, width = Auto()) - -save("example_lslider.svg", fig); nothing # hide -``` - -![example lslider](example_lslider.svg) - -To create a horizontal layout containing a label, a slider, and a value label, use the convenience function [`AbstractPlotting.MakieLayout.labelslider!`](@ref), or, if you need multiple aligned rows of sliders, use [`AbstractPlotting.MakieLayout.labelslidergrid!`](@ref). - -```@example -using CairoMakie -fig = Figure(resolution = (1200, 900)) - -Axis(fig[1, 1]) - -lsgrid = labelslidergrid!( - fig, - ["Voltage", "Current", "Resistance"], - # use Ref for the same range for every slider via internal broadcasting - Ref(LinRange(0:0.1:1000)); - formats = [x -> "$(round(x, digits = 1))$s" for s in ["V", "A", "Ω"]], - width = 350, - tellheight = false) - -fig[1, 2] = lsgrid.layout - -set_close_to!(lsgrid.sliders[1], 230.3) -set_close_to!(lsgrid.sliders[2], 628.4) -set_close_to!(lsgrid.sliders[3], 15.9) - -save("example_labelslidergrid.svg", fig); nothing # hide -``` - -![example labelslidergrid](example_labelslidergrid.svg) - -If you want to programmatically move the slider, use the function [`AbstractPlotting.MakieLayout.set_close_to!`](@ref). -Don't manipulate the `value` attribute directly, as there is no guarantee that -this value exists in the range underlying the slider, and the slider's displayed value would -not change anyway by changing the slider's output. - -## Label - -This is just normal text, except it's also layoutable. A text's size is known, -so rows and columns in a GridLayout can shrink to the appropriate width or height. - -```@example -using CairoMakie - -fig = Figure(resolution = (1200, 900)) - -fig[1:2, 1:3] = [Axis(fig) for _ in 1:6] - -supertitle = Label(fig[0, :], "Six plots", textsize = 30) - -sideinfo = Label(fig[2:3, 0], "This text is vertical", rotation = pi/2) - -save("example_ltext.svg", fig); nothing # hide -``` - -![example ltext](example_ltext.svg) - -## Button - -```@example -using CairoMakie - -fig = Figure(resolution = (1200, 900)) - -Axis(fig[1, 1]) -fig[2, 1] = buttongrid = GridLayout(tellwidth = false) - -buttons = buttongrid[1, 1:5] = [Button(fig, label = "Button $i") for i in 1:5] - -for button in buttons - on(button.clicks) do n - println("$(button.label[]) was clicked $n times.") - end -end - -fig - -save("example_lbutton.svg", fig); nothing # hide -``` - -![example lbutton](example_lbutton.svg) - - -## Box - -A simple rectangle poly that is layoutable. This can be useful to make boxes for -facet plots or when a rectangular placeholder is needed. - -```@example -using CairoMakie -using ColorSchemes - -fig = Figure(resolution = (1200, 900)) - -rects = fig[1:4, 1:6] = [ - Box(fig, color = c) - for c in get.(Ref(ColorSchemes.rainbow), (0:23) ./ 23)] - -save("example_lrect.svg", fig); nothing # hide -``` - -![example lrect](example_lrect.svg) - -## LScene - -If you need a normal Makie scene in a layout, for example for 3D plots, you have -to use `LScene` right now. It's just a wrapper around the normal `Scene` that -makes it layoutable. The underlying Scene is accessible via the `scene` field. -You can plot into the `LScene` directly, though. - -You can pass keyword arguments to the underlying `Scene` object to the `scenekw` keyword. -Currently, it can be necessary to pass a couple of attributes explicitly to make sure they -are not inherited from the main scene (which has a pixel camera and no axis, e.g.). - -```julia -using CairoMakie - -fig = Figure(resolution = (1200, 900)) - -lscene = LScene(fig[1, 1], scenekw = (camera = cam3d!, raw = false)) - -# now you can plot into lscene like you're used to -scatter!(lscene, randn(100, 3)) -``` - - -## Toggle - -A toggle with an attribute `active` that can either be true or false, to enable -or disable properties of an interactive plot. - -```@example -using CairoMakie - -fig = Figure(resolution = (1200, 900)) - -ax = Axis(fig[1, 1]) - -toggles = [Toggle(fig, active = ac) for ac in [true, false]] -labels = [Label(fig, lift(x -> x ? "active" : "inactive", t.active)) - for t in toggles] - -fig[1, 2] = grid!(hcat(toggles, labels), tellheight = false) - -save("example_ltoggle.svg", fig); nothing # hide -``` - -![example ltoggle](example_ltoggle.svg) - - -## Menu - -A dropdown menu with `options`, where each element's label is determined with `optionlabel(element)` -and the value with `optionvalue(element)`. The default behavior is to treat a 2-element tuple -as `(label, value)` and any other object as `value`, where `label = string(value)`. - -The attribute `selection` is set to `optionvalue(element)` when the element's entry is selected. - - - -```@example -using CairoMakie - -fig = Figure(resolution = (1200, 900)) - -menu = Menu(fig, options = ["viridis", "heat", "blues"]) - -funcs = [sqrt, x->x^2, sin, cos] - -menu2 = Menu(fig, options = zip(["Square Root", "Square", "Sine", "Cosine"], funcs)) - -fig[1, 1] = vgrid!( - Label(fig, "Colormap", width = nothing), - menu, - Label(fig, "Function", width = nothing), - menu2; - tellheight = false, width = 200) - -ax = Axis(fig[1, 2]) - -func = Node{Any}(funcs[1]) - -ys = @lift($func.(0:0.3:10)) -scat = scatter!(ax, ys, markersize = 10px, color = ys) - -cb = Colorbar(fig[1, 3], scat, width = 30) - -on(menu.selection) do s - scat.colormap = s -end - -on(menu2.selection) do s - func[] = s - autolimits!(ax) -end - -menu2.is_open = true - -save("example_lmenu.svg", fig); nothing # hide -``` - -![example lmenu](example_lmenu.svg) - - -## Deleting Layoutables - -To remove axes, colorbars and other layoutables from their layout and the figure or scene, -use `delete!(layoutable)`. - -```@eval -using GLMakie -GLMakie.activate!() -``` diff --git a/docs/src/makielayout/layouting.md b/docs/src/makielayout/layouting.md index 96b9f480e..4660833da 100755 --- a/docs/src/makielayout/layouting.md +++ b/docs/src/makielayout/layouting.md @@ -1,4 +1,4 @@ -## How layouting works +# How layouts work The goal of MakieLayout is that all elements placed in a scene fit into the window, fill the available space, and are nicely aligned relative to each other. diff --git a/docs/src/makielayout/llegend.md b/docs/src/makielayout/legend.md similarity index 99% rename from docs/src/makielayout/llegend.md rename to docs/src/makielayout/legend.md index d5fe7c5db..faae268f5 100755 --- a/docs/src/makielayout/llegend.md +++ b/docs/src/makielayout/legend.md @@ -3,6 +3,8 @@ using CairoMakie CairoMakie.activate!() ``` +# Legend + ## Creating A Legend From Elements You can create a basic Legend by passing a vector of legend entries and a vector of labels, plus an optional title as the third argument. diff --git a/docs/src/makielayout/lscene.md b/docs/src/makielayout/lscene.md new file mode 100644 index 000000000..e84932c1a --- /dev/null +++ b/docs/src/makielayout/lscene.md @@ -0,0 +1,26 @@ +```@eval +using CairoMakie +CairoMakie.activate!() +``` + +# LScene + +If you need a normal Makie scene in a layout, for example for 3D plots, you have +to use `LScene` right now. It's just a wrapper around the normal `Scene` that +makes it layoutable. The underlying Scene is accessible via the `scene` field. +You can plot into the `LScene` directly, though. + +You can pass keyword arguments to the underlying `Scene` object to the `scenekw` keyword. +Currently, it can be necessary to pass a couple of attributes explicitly to make sure they +are not inherited from the main scene (which has a pixel camera and no axis, e.g.). + +```julia +using CairoMakie + +fig = Figure(resolution = (1200, 900)) + +lscene = LScene(fig[1, 1], scenekw = (camera = cam3d!, raw = false)) + +# now you can plot into lscene like you're used to +scatter!(lscene, randn(100, 3)) +``` \ No newline at end of file diff --git a/docs/src/makielayout/menu.md b/docs/src/makielayout/menu.md new file mode 100644 index 000000000..7d5c3b046 --- /dev/null +++ b/docs/src/makielayout/menu.md @@ -0,0 +1,57 @@ +```@eval +using CairoMakie +CairoMakie.activate!() +``` + +# Menu + +A dropdown menu with `options`, where each element's label is determined with `optionlabel(element)` +and the value with `optionvalue(element)`. The default behavior is to treat a 2-element tuple +as `(label, value)` and any other object as `value`, where `label = string(value)`. + +The attribute `selection` is set to `optionvalue(element)` when the element's entry is selected. + + + +```@example +using CairoMakie + +fig = Figure(resolution = (1200, 900)) + +menu = Menu(fig, options = ["viridis", "heat", "blues"]) + +funcs = [sqrt, x->x^2, sin, cos] + +menu2 = Menu(fig, options = zip(["Square Root", "Square", "Sine", "Cosine"], funcs)) + +fig[1, 1] = vgrid!( + Label(fig, "Colormap", width = nothing), + menu, + Label(fig, "Function", width = nothing), + menu2; + tellheight = false, width = 200) + +ax = Axis(fig[1, 2]) + +func = Node{Any}(funcs[1]) + +ys = @lift($func.(0:0.3:10)) +scat = scatter!(ax, ys, markersize = 10px, color = ys) + +cb = Colorbar(fig[1, 3], scat, width = 30) + +on(menu.selection) do s + scat.colormap = s +end + +on(menu2.selection) do s + func[] = s + autolimits!(ax) +end + +menu2.is_open = true + +save("example_lmenu.svg", fig); nothing # hide +``` + +![example lmenu](example_lmenu.svg) \ No newline at end of file diff --git a/docs/src/makielayout/slider.md b/docs/src/makielayout/slider.md new file mode 100644 index 000000000..bcfa3ecab --- /dev/null +++ b/docs/src/makielayout/slider.md @@ -0,0 +1,62 @@ +```@eval +using CairoMakie +CairoMakie.activate!() +``` + +# Slider + +A simple slider without a label. You can create a label using a `Label` object, +for example. You need to specify a range that constrains the slider's possible values. +You can then lift the `value` observable to make interactive plots. + +```@example +using CairoMakie + +fig = Figure(resolution = (1200, 900)) + +Axis(fig[1, 1]) +sl1 = Slider(fig[2, 1], range = 0:0.01:10, startvalue = 3) +sl2 = Slider(fig[3, 1], range = 0:0.01:10, startvalue = 5) +sl3 = Slider(fig[4, 1], range = 0:0.01:10, startvalue = 7) + +sl4 = Slider(fig[:, 2], range = 0:0.01:10, horizontal = false, + tellwidth = true, height = nothing, width = Auto()) + +save("example_lslider.svg", fig); nothing # hide +``` + +![example lslider](example_lslider.svg) + +To create a horizontal layout containing a label, a slider, and a value label, use the convenience function [`AbstractPlotting.MakieLayout.labelslider!`](@ref), or, if you need multiple aligned rows of sliders, use [`AbstractPlotting.MakieLayout.labelslidergrid!`](@ref). + +```@example +using CairoMakie +fig = Figure(resolution = (1200, 900)) + +Axis(fig[1, 1]) + +lsgrid = labelslidergrid!( + fig, + ["Voltage", "Current", "Resistance"], + # use Ref for the same range for every slider via internal broadcasting + Ref(LinRange(0:0.1:1000)); + formats = [x -> "$(round(x, digits = 1))$s" for s in ["V", "A", "Ω"]], + width = 350, + tellheight = false) + +fig[1, 2] = lsgrid.layout + +set_close_to!(lsgrid.sliders[1], 230.3) +set_close_to!(lsgrid.sliders[2], 628.4) +set_close_to!(lsgrid.sliders[3], 15.9) + +save("example_labelslidergrid.svg", fig); nothing # hide +``` + +![example labelslidergrid](example_labelslidergrid.svg) + +If you want to programmatically move the slider, use the function [`AbstractPlotting.MakieLayout.set_close_to!`](@ref). +Don't manipulate the `value` attribute directly, as there is no guarantee that +this value exists in the range underlying the slider, and the slider's displayed value would +not change anyway by changing the slider's output. + diff --git a/docs/src/makielayout/toggle.md b/docs/src/makielayout/toggle.md new file mode 100644 index 000000000..a18e8817c --- /dev/null +++ b/docs/src/makielayout/toggle.md @@ -0,0 +1,27 @@ +```@eval +using CairoMakie +CairoMakie.activate!() +``` + +# Toggle + +A toggle with an attribute `active` that can either be true or false, to enable +or disable properties of an interactive plot. + +```@example +using CairoMakie + +fig = Figure(resolution = (1200, 900)) + +ax = Axis(fig[1, 1]) + +toggles = [Toggle(fig, active = ac) for ac in [true, false]] +labels = [Label(fig, lift(x -> x ? "active" : "inactive", t.active)) + for t in toggles] + +fig[1, 2] = grid!(hcat(toggles, labels), tellheight = false) + +save("example_ltoggle.svg", fig); nothing # hide +``` + +![example ltoggle](example_ltoggle.svg) \ No newline at end of file diff --git a/docs/src/plotting_functions.md b/docs/src/plotting_functions.md deleted file mode 100644 index 29d8bdfd3..000000000 --- a/docs/src/plotting_functions.md +++ /dev/null @@ -1,538 +0,0 @@ -# Plotting Functions - -On this page, the basic plotting functions are listed together with examples of their usage and available attributes. - -```@contents -Pages = ["plotting_functions.md"] -Depth = 2 -``` - -## `arrows` - -```@docs -arrows -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = LinRange(1, 10, 20) -ys = LinRange(1, 15, 20) -us = [cos(x) for x in xs, y in ys] -vs = [sin(y) for x in xs, y in ys] - -arrows(xs, ys, us, vs, arrowsize = 0.2, lengthscale = 0.3) -``` - -## `band` - -```@docs -band -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = 1:0.2:10 -ys_low = -0.2 .* sin.(xs) .- 0.25 -ys_high = 0.2 .* sin.(xs) .+ 0.25 - -band(xs, ys_low, ys_high) -band!(xs, ys_low .- 1, ys_high .-1, color = :red) -current_figure() -``` - -## `barplot` - -```@docs -barplot -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = 1:0.2:10 -ys = 0.5 .* sin.(xs) - -barplot(xs, ys, color = :red, strokecolor = :black, strokewidth = 1) -barplot!(xs, ys .- 1, fillto = -1, color = xs, strokecolor = :black, strokewidth = 1) -current_figure() -``` - -## `contour` - -```@docs -contour -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = LinRange(0, 10, 100) -ys = LinRange(0, 15, 100) -zs = [cos(x) * sin(y) for x in xs, y in ys] - -contour(xs, ys, zs) -``` - -## `contourf` - -```@docs -contourf -``` - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = LinRange(0, 10, 100) -ys = LinRange(0, 10, 100) -zs = [cos(x) * sin(y) for x in xs, y in ys] - -f = Figure() - -_, co1 = contourf(f[1, 1][1, 1], xs, ys, zs, levels = 10) -Colorbar(f[1, 1][1, 2], co1, width = 20) - -_, co2 = contourf(f[1, 2][1, 1], xs, ys, zs, levels = -0.75:0.25:0.5, - extendlow = :cyan, extendhigh = :magenta) -Colorbar(f[1, 2][1, 2], co2, width = 20) - -_, co3 = contourf(f[2, 1][1, 1], xs, ys, zs, - levels = -0.75:0.25:0.5, - extendlow = :auto, extendhigh = :auto) -Colorbar(f[2, 1][1, 2], co3, width = 20) - -f -``` - -## `density` - -```@docs -density -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -f = Figure() - -density(f[1, 1], randn(200)) -density(f[1, 2], randn(200), direction = :y, npoints = 10) -density(f[2, 1], randn(200), color = (:red, 0.3), - strokecolor = :red, strokewidth = 3, strokearound = true) - -ax = f[2, 2] = Axis(f) -data = [randn(1000) .+ i/2 for i in 0:5] -for (i, da) in enumerate(data) - density!(da, offset = -i/4, color = (:slategray, 0.4), - bandwidth = 0.1) -end -f -``` - -## `errorbars` - -```@docs -errorbars -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = 0:0.5:10 -ys1 = 0.5 .* sin.(xs) -ys2 = ys1 .- 1 -ys3 = ys1 .- 2 - -lowerrors = fill(0.1, length(xs)) -higherrors = LinRange(0.1, 0.4, length(xs)) - - -errorbars(xs, ys1, higherrors, color = :red) # same low and high error -errorbars!(xs, ys2, lowerrors, higherrors, color = LinRange(0, 1, length(xs))) -errorbars!(xs, ys3, lowerrors, higherrors, whiskerwidth = 3, direction = :x) - -# plot position scatters so low and high errors can be discriminated -scatter!(xs, ys1, markersize = 3, color = :black) -scatter!(xs, ys2, markersize = 3, color = :black) -scatter!(xs, ys3, markersize = 3, color = :black) -current_figure() -``` - -## `heatmap` - -```@docs -heatmap -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = LinRange(0, 10, 100) -ys = LinRange(0, 15, 100) -zs = [cos(x) * sin(y) for x in xs, y in ys] - -heatmap(xs, ys, zs) -``` - -## `hist` - -```@docs -hist -``` - -### Examples - -```julia -using GLMakie -AbstractPlotting.inline!(true) # hide - -data = randn(1000) - -f = Figure() -hist(f[1, 1], data, bins = 10) -hist(f[1, 2], data, bins = 20, color = :red, strokewidth = 1, strokecolor = :black) -hist(f[2, 1], data, bins = [-5, -2, -1, 0, 1, 2, 5], color = :gray) -hist(f[2, 2], data, normalization = :pdf) -f -``` - -## `image` - -```@docs -image -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide -using FileIO - -img = rotr90(load("assets/cow.png")) - -image(img) -``` - - -## `lines` - -```@docs -lines -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = 0:0.01:10 -ys = 0.5 .* sin.(xs) - -lines(xs, ys) -lines!(xs, ys .- 1, linewidth = 5) -lines!(xs, ys .- 2, linewidth = 5, color = ys) -lines!(xs, ys .- 3, linestyle = :dash) -current_figure() -``` - -## `linesegments` - -```@docs -linesegments -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = 1:0.2:10 -ys = sin.(xs) - -linesegments(xs, ys) -linesegments!(xs, ys .- 1, linewidth = 5) -linesegments!(xs, ys .- 2, linewidth = LinRange(1, 10, length(xs))) -linesegments!(xs, ys .- 3, linewidth = 5, color = LinRange(1, 5, length(xs))) -current_figure() -``` - - -## `mesh` - -```@docs -mesh -``` - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -vertices = [ - 0.0 0.0; - 1.0 0.0; - 1.0 1.0; - 0.0 1.0; -] - -faces = [ - 1 2 3; - 3 4 1; -] - -colors = [:red, :green, :blue, :orange] - -scene = mesh(vertices, faces, color = colors, shading = false) -``` - -## `meshscatter` - -```@docs -meshscatter -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = cos.(1:0.5:20) -ys = sin.(1:0.5:20) -zs = LinRange(0, 3, length(xs)) - -meshscatter(xs, ys, zs, markersize = 0.1, color = zs) -``` - - -## `poly` - -```@docs -poly -``` - -### Examples - -```@example -using GLMakie -using AbstractPlotting.GeometryBasics -AbstractPlotting.inline!(true) # hide - - -f, _ = poly(Point2f0[(0, 0), (2, 0), (3, 1), (1, 1)], color = :red, strokecolor = :black, strokewidth = 1) - -# polygon with hole -p = Polygon( - Point2f0[(0, 0), (2, 0), (3, 1), (1, 1)], - [Point2f0[(0.75, 0.25), (1.75, 0.25), (2.25, 0.75), (1.25, 0.75)]] -) -poly(f[1, 2], p, color = :blue) - -# vector of shapes -poly(f[2, 1], - [Rect(i, j, 0.75, 0.5) for i in 1:5 for j in 1:3], - color = 1:15, - colormap = :heat -) - -# shape decomposition -poly(f[2, 2], Circle(Point2f0(0, 0), 15f0), color = :pink, - axis = (autolimitaspect = 1,)) - -# vector of polygons -ps = [Polygon(rand(Point2f0, 3) .+ Point2f0(i, j)) - for i in 1:5 for j in 1:10] -poly(f[1:2, 3], ps, color = rand(RGBf0, length(ps)), - axis = (backgroundcolor = :gray15,)) - -f -``` - -## `rangebars` - -```@docs -rangebars -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -vals = -1:0.1:1 - -lows = zeros(length(vals)) -highs = LinRange(0.1, 0.4, length(vals)) - - -rangebars(vals, lows, highs, color = :red) -rangebars!(vals, lows, highs, color = LinRange(0, 1, length(vals)), - whiskerwidth = 3, direction = :x) -current_figure() -``` - -## `scatter` - -```@docs -scatter -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = LinRange(0, 10, 20) -ys = 0.5 .* sin.(xs) - -scatter(xs, ys, color = :red) -scatter!(xs, ys .- 1, color = xs) -scatter!(xs, ys .- 2, markersize = LinRange(5, 30, 20)) -scatter!(xs, ys .- 3, marker = 'a':'t', strokewidth = 0, color = :black) -current_figure() -``` - -## `scatterlines` - -```@docs -scatterlines -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = LinRange(0, 10, 20) -ys = 0.5 .* sin.(xs) - -scatterlines(xs, ys, color = :red) -scatterlines!(xs, ys .- 1, color = xs, markercolor = :red) -scatterlines!(xs, ys .- 2, markersize = LinRange(5, 30, 20)) -scatterlines!(xs, ys .- 3, marker = :cross, strokewidth = 0, - strokecolor = :red, markercolor = :cyan) -current_figure() -``` - - -## `stem` - -```@docs -stem -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = LinRange(0, 4pi, 30) - -f = Figure() -stem(f[1, 1], xs, sin.(xs)) -stem(f[1, 2], xs, sin, - offset = 0.5, trunkcolor = :blue, marker = :rect, - stemcolor = :red, color = :orange, - markersize = 15, strokecolor = :red, strokewidth = 3, - trunklinestyle = :dash, stemlinestyle = :dashdot) -stem(f[2, 1], xs, sin.(xs), - offset = LinRange(-0.5, 0.5, 30), - color = LinRange(0, 1, 30), colorrange = (0, 0.5), - trunkcolor = LinRange(0, 1, 30), trunkwidth = 5) -stem(f[2, 2], 0.5xs, 2 .* sin.(xs), 2 .* cos.(xs), - offset = Point3f0.(0.5xs, sin.(xs), cos.(xs)), - stemcolor = LinRange(0, 1, 30), stemcolormap = :Spectral, stemcolorrange = (0, 0.5)) -f -``` - - -## `surface` - -```@docs -surface -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -xs = LinRange(0, 10, 100) -ys = LinRange(0, 15, 100) -zs = [cos(x) * sin(y) for x in xs, y in ys] - -surface(xs, ys, zs) -``` - -## `text` - -```@docs -text -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -scene = Scene(camera = campixel!, show_axis = false, resolution = (600, 600)) - -text!(scene, "AbstractPlotting", position = Point2f0(300, 500), - textsize = 30, align = (:left, :bottom), show_axis = false) -text!(scene, "AbstractPlotting", position = Point2f0(300, 400), - color = :red, textsize = 30, align = (:right, :center), show_axis = false) -text!(scene, "AbstractPlotting\nMakie", position = Point2f0(300, 300), - color = :blue, textsize = 30, align = (:center, :center), show_axis = false) -text!(scene, "AbstractPlotting\nMakie", position = Point2f0(300, 200), - color = :green, textsize = 30, align = (:center, :top), rotation = pi/4, show_axis = false) -``` - -## `volume` - -```@docs -volume -``` - -### Examples - -```@example -using GLMakie -AbstractPlotting.inline!(true) # hide - -r = LinRange(-1, 1, 100) -cube = [(x.^2 + y.^2 + z.^2) for x = r, y = r, z = r] -cube_with_holes = cube .* (cube .> 1.4) - -volume(cube_with_holes, algorithm = :iso, isorange = 0.05, isovalue = 1.7) -``` diff --git a/docs/src/plotting_functions/arrows.md b/docs/src/plotting_functions/arrows.md new file mode 100644 index 000000000..7ccf05342 --- /dev/null +++ b/docs/src/plotting_functions/arrows.md @@ -0,0 +1,26 @@ +# arrows + +```@docs +arrows +``` + +### Examples + +```@example +using GLMakie +GLMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = LinRange(1, 10, 20) +ys = LinRange(1, 15, 20) +us = [cos(x) for x in xs, y in ys] +vs = [sin(y) for x in xs, y in ys] + +arrows!(xs, ys, us, vs, arrowsize = 0.2, lengthscale = 0.3) + +f +``` + diff --git a/docs/src/plotting_functions/band.md b/docs/src/plotting_functions/band.md new file mode 100644 index 000000000..3279e19bc --- /dev/null +++ b/docs/src/plotting_functions/band.md @@ -0,0 +1,28 @@ +# band + +```@docs +band +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = 1:0.2:10 +ys_low = -0.2 .* sin.(xs) .- 0.25 +ys_high = 0.2 .* sin.(xs) .+ 0.25 + +band!(xs, ys_low, ys_high) +band!(xs, ys_low .- 1, ys_high .-1, color = :red) + +f +save("example_band.svg", f); nothing # hide +``` + +![example band](example_band.svg) diff --git a/docs/src/plotting_functions/barplot.md b/docs/src/plotting_functions/barplot.md new file mode 100644 index 000000000..ada502740 --- /dev/null +++ b/docs/src/plotting_functions/barplot.md @@ -0,0 +1,29 @@ +# barplot + +```@docs +barplot +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = 1:0.2:10 +ys = 0.5 .* sin.(xs) + +barplot!(xs, ys, color = :red, strokecolor = :black, strokewidth = 1) +barplot!(xs, ys .- 1, fillto = -1, color = xs, strokecolor = :black, strokewidth = 1) + +f +save("example_barplot.svg", f); nothing # hide +``` + +![example barplot](example_barplot.svg) + + diff --git a/docs/src/plotting_functions/contour.md b/docs/src/plotting_functions/contour.md new file mode 100644 index 000000000..0d5b6ab44 --- /dev/null +++ b/docs/src/plotting_functions/contour.md @@ -0,0 +1,28 @@ +# contour + +```@docs +contour +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = LinRange(0, 10, 100) +ys = LinRange(0, 15, 100) +zs = [cos(x) * sin(y) for x in xs, y in ys] + +contour!(xs, ys, zs) + +f +save("example_contour.svg", f); nothing # hide +``` + +![example contour](example_contour.svg) + diff --git a/docs/src/plotting_functions/contourf.md b/docs/src/plotting_functions/contourf.md new file mode 100644 index 000000000..530cad948 --- /dev/null +++ b/docs/src/plotting_functions/contourf.md @@ -0,0 +1,77 @@ +# contourf + +```@docs +contourf +``` + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +xs = LinRange(0, 10, 100) +ys = LinRange(0, 10, 100) +zs = [cos(x) * sin(y) for x in xs, y in ys] + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +co = contourf!(xs, ys, zs, levels = 10) + +Colorbar(f[1, 2], co, width = 20) + +f +save("example_contourf_1.svg", f); nothing # hide +``` + +![example_contourf_1](example_contourf_1.svg) + + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +xs = LinRange(0, 10, 100) +ys = LinRange(0, 10, 100) +zs = [cos(x) * sin(y) for x in xs, y in ys] + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +co = contourf!(xs, ys, zs, levels = -0.75:0.25:0.5, + extendlow = :cyan, extendhigh = :magenta) + +Colorbar(f[1, 2], co, width = 20) + +f +save("example_contourf_2.svg", f); nothing # hide +``` + +![example_contourf_2](example_contourf_2.svg) + + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +xs = LinRange(0, 10, 100) +ys = LinRange(0, 10, 100) +zs = [cos(x) * sin(y) for x in xs, y in ys] + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +co = contourf!(xs, ys, zs, + levels = -0.75:0.25:0.5, + extendlow = :auto, extendhigh = :auto) + +Colorbar(f[1, 2], co, width = 20) + +f +save("example_contourf_3.svg", f); nothing # hide +``` + +![example_contourf_3](example_contourf_3.svg) + diff --git a/docs/src/plotting_functions/density.md b/docs/src/plotting_functions/density.md new file mode 100644 index 000000000..9551705cd --- /dev/null +++ b/docs/src/plotting_functions/density.md @@ -0,0 +1,87 @@ +# density + +```@docs +density +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +density!(randn(200)) + +f +save("example_density_1.svg", f); nothing # hide +``` + +![example_density_1](example_density_1.svg) + + + + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +density!(randn(200), direction = :y, npoints = 10) + +f +save("example_density_2_.svg", f); nothing # hide +``` + +![example_density_2_](example_density_2_.svg) + + + + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +density!(randn(200), color = (:red, 0.3), + strokecolor = :red, strokewidth = 3, strokearound = true) + +f +save("example_density_3.svg", f); nothing # hide +``` + +![example_density_3](example_density_3.svg) + + + + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +vectors = [randn(1000) .+ i/2 for i in 0:5] + +for (i, vector) in enumerate(vectors) + density!(vector, offset = -i/4, color = (:slategray, 0.4), + bandwidth = 0.1) +end + +f +save("example_density_4_.svg", f); nothing # hide +``` + +![example_density_4_](example_density_4_.svg) + diff --git a/docs/src/plotting_functions/errorbars.md b/docs/src/plotting_functions/errorbars.md new file mode 100644 index 000000000..21676599c --- /dev/null +++ b/docs/src/plotting_functions/errorbars.md @@ -0,0 +1,87 @@ +# errorbars + +```@docs +errorbars +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = 0:0.5:10 +ys = 0.5 .* sin.(xs) + +lowerrors = fill(0.1, length(xs)) +higherrors = LinRange(0.1, 0.4, length(xs)) + +errorbars!(xs, ys, higherrors, color = :red) # same low and high error + +# plot position scatters so low and high errors can be discriminated +scatter!(xs, ys, markersize = 3, color = :black) + +f +save("example_errorbars_1.svg", f); nothing # hide +``` + + + +![example_errorbars_1](example_errorbars_1.svg) + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = 0:0.5:10 +ys = 0.5 .* sin.(xs) + +lowerrors = fill(0.1, length(xs)) +higherrors = LinRange(0.1, 0.4, length(xs)) + +errorbars!(xs, ys, lowerrors, higherrors, color = LinRange(0, 1, length(xs))) + +# plot position scatters so low and high errors can be discriminated +scatter!(xs, ys, markersize = 3, color = :black) + +f +save("example_errorbars_2_.svg", f); nothing # hide +``` + +![example_errorbars_2_](example_errorbars_2_.svg) + + + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = 0:0.5:10 +ys = 0.5 .* sin.(xs) + +lowerrors = fill(0.1, length(xs)) +higherrors = LinRange(0.1, 0.4, length(xs)) + +errorbars!(xs, ys, lowerrors, higherrors, whiskerwidth = 3, direction = :x) + +# plot position scatters so low and high errors can be discriminated +scatter!(xs, ys, markersize = 3, color = :black) + +f +save("example_errorbars_3_.svg", f); nothing # hide +``` + +![example_errorbars_3_](example_errorbars_3_.svg) + diff --git a/docs/src/plotting_functions/heatmap.md b/docs/src/plotting_functions/heatmap.md new file mode 100644 index 000000000..aedf36645 --- /dev/null +++ b/docs/src/plotting_functions/heatmap.md @@ -0,0 +1,30 @@ +# heatmap + +```@docs +heatmap +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = LinRange(0, 10, 100) +ys = LinRange(0, 15, 100) +zs = [cos(x) * sin(y) for x in xs, y in ys] + +heatmap!(xs, ys, zs) + +f +save("example_heatmap_1.svg", f); nothing # hide +``` + +![example_heatmap_1](example_heatmap_1.svg) + + diff --git a/docs/src/plotting_functions/hist.md b/docs/src/plotting_functions/hist.md new file mode 100644 index 000000000..968bb5576 --- /dev/null +++ b/docs/src/plotting_functions/hist.md @@ -0,0 +1,23 @@ +# hist + +```@docs +hist +``` + +### Examples + +```julia +using GLMakie +GLMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +data = randn(1000) + +f = Figure() +hist(f[1, 1], data, bins = 10) +hist(f[1, 2], data, bins = 20, color = :red, strokewidth = 1, strokecolor = :black) +hist(f[2, 1], data, bins = [-5, -2, -1, 0, 1, 2, 5], color = :gray) +hist(f[2, 2], data, normalization = :pdf) +f +``` + diff --git a/docs/src/plotting_functions/image.md b/docs/src/plotting_functions/image.md new file mode 100644 index 000000000..c0e90cc46 --- /dev/null +++ b/docs/src/plotting_functions/image.md @@ -0,0 +1,28 @@ +# image + +```@docs +image +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide +using FileIO + +img = rotr90(load("../assets/cow.png")) + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1], aspect = DataAspect()) + +image!(img) + +f +save("example_image_1.svg", f); nothing # hide +``` + +![example_image_1](example_image_1.svg) + + diff --git a/docs/src/plotting_functions/lines.md b/docs/src/plotting_functions/lines.md new file mode 100644 index 000000000..c43344548 --- /dev/null +++ b/docs/src/plotting_functions/lines.md @@ -0,0 +1,29 @@ +# lines + +```@docs +lines +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = 0:0.01:10 +ys = 0.5 .* sin.(xs) + +lines!(xs, ys) +lines!(xs, ys .- 1, linewidth = 5) +lines!(xs, ys .- 2, linewidth = 5, color = ys) +lines!(xs, ys .- 3, linestyle = :dash) + +f +save("example_lines_1.svg", f); nothing # hide +``` + +![example_lines_1](example_lines_1.svg) diff --git a/docs/src/plotting_functions/linesegments.md b/docs/src/plotting_functions/linesegments.md new file mode 100644 index 000000000..7ccf0b157 --- /dev/null +++ b/docs/src/plotting_functions/linesegments.md @@ -0,0 +1,30 @@ +# linesegments + +```@docs +linesegments +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = 1:0.2:10 +ys = sin.(xs) + +linesegments!(xs, ys) +linesegments!(xs, ys .- 1, linewidth = 5) +linesegments!(xs, ys .- 2, linewidth = 5, color = LinRange(1, 5, length(xs))) + +f +save("example_linesegments.svg", f); nothing # hide +``` + +![example linesegments](example_linesegments.svg) + + diff --git a/docs/src/plotting_functions/mesh.md b/docs/src/plotting_functions/mesh.md new file mode 100644 index 000000000..c5d580626 --- /dev/null +++ b/docs/src/plotting_functions/mesh.md @@ -0,0 +1,28 @@ +# mesh + +```@docs +mesh +``` + +```@example +using GLMakie +GLMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +vertices = [ + 0.0 0.0; + 1.0 0.0; + 1.0 1.0; + 0.0 1.0; +] + +faces = [ + 1 2 3; + 3 4 1; +] + +colors = [:red, :green, :blue, :orange] + +scene = mesh(vertices, faces, color = colors, shading = false) +``` + diff --git a/docs/src/plotting_functions/meshscatter.md b/docs/src/plotting_functions/meshscatter.md new file mode 100644 index 000000000..48ad0992e --- /dev/null +++ b/docs/src/plotting_functions/meshscatter.md @@ -0,0 +1,21 @@ +# meshscatter + +```@docs +meshscatter +``` + +### Examples + +```@example +using GLMakie +GLMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +xs = cos.(1:0.5:20) +ys = sin.(1:0.5:20) +zs = LinRange(0, 3, length(xs)) + +meshscatter(xs, ys, zs, markersize = 0.1, color = zs) +``` + + diff --git a/docs/src/plotting_functions/poly.md b/docs/src/plotting_functions/poly.md new file mode 100644 index 000000000..73161f23b --- /dev/null +++ b/docs/src/plotting_functions/poly.md @@ -0,0 +1,113 @@ +# poly + +```@docs +poly +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +using AbstractPlotting.GeometryBasics +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +poly!(Point2f0[(0, 0), (2, 0), (3, 1), (1, 1)], color = :red, strokecolor = :black, strokewidth = 1) + +f +save("example_poly_1.svg", f); nothing # hide +``` + +![example_poly_1](example_poly_1.svg) + + + +```@example +using CairoMakie +CairoMakie.activate!() # hide +using AbstractPlotting.GeometryBasics +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +# polygon with hole +p = Polygon( + Point2f0[(0, 0), (2, 0), (3, 1), (1, 1)], + [Point2f0[(0.75, 0.25), (1.75, 0.25), (2.25, 0.75), (1.25, 0.75)]] +) + +poly!(p, color = :blue) + +f +save("example_poly_2_.svg", f); nothing # hide +``` + +![example_poly_2_](example_poly_2_.svg) + +```@example +using CairoMakie +CairoMakie.activate!() # hide +using AbstractPlotting.GeometryBasics +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +# vector of shapes +poly!( + [Rect(i, j, 0.75, 0.5) for i in 1:5 for j in 1:3], + color = 1:15, + colormap = :heat +) + +f +save("example_poly_3.svg", f); nothing # hide +``` + +![example_poly_3](example_poly_3.svg) + + + +```@example +using CairoMakie +CairoMakie.activate!() # hide +using AbstractPlotting.GeometryBasics +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1], aspect = DataAspect()) + +# shape decomposition +poly!(Circle(Point2f0(0, 0), 15f0), color = :pink) + +f +save("example_poly_4.svg", f); nothing # hide +``` + +![example_poly_4](example_poly_4.svg) + +```@example +using CairoMakie +CairoMakie.activate!() # hide +using AbstractPlotting.GeometryBasics +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +# vector of polygons +ps = [Polygon(rand(Point2f0, 3) .+ Point2f0(i, j)) + for i in 1:5 for j in 1:10] + +poly!(ps, color = rand(RGBf0, length(ps)), + axis = (backgroundcolor = :gray15,)) + +f +save("example_poly_5.svg", f); nothing # hide +``` + +![example_poly_5](example_poly_5.svg) diff --git a/docs/src/plotting_functions/rangebars.md b/docs/src/plotting_functions/rangebars.md new file mode 100644 index 000000000..20a50865d --- /dev/null +++ b/docs/src/plotting_functions/rangebars.md @@ -0,0 +1,51 @@ +# rangebars + +```@docs +rangebars +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +vals = -1:0.1:1 +lows = zeros(length(vals)) +highs = LinRange(0.1, 0.4, length(vals)) + +rangebars!(vals, lows, highs, color = :red) + +f +save("example_rangebars_1.svg", f); nothing # hide +``` + +![example_rangebars_1](example_rangebars_1.svg) + + + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +vals = -1:0.1:1 +lows = zeros(length(vals)) +highs = LinRange(0.1, 0.4, length(vals)) + +rangebars!(vals, lows, highs, color = LinRange(0, 1, length(vals)), + whiskerwidth = 3, direction = :x) + +f +save("example_rangebars_2.svg", f); nothing # hide +``` + +![example_rangebars_2](example_rangebars_2.svg) + diff --git a/docs/src/plotting_functions/scatter.md b/docs/src/plotting_functions/scatter.md new file mode 100644 index 000000000..c08b4bbe1 --- /dev/null +++ b/docs/src/plotting_functions/scatter.md @@ -0,0 +1,30 @@ +# scatter + +```@docs +scatter +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = LinRange(0, 10, 20) +ys = 0.5 .* sin.(xs) + +scatter!(xs, ys, color = :red) +scatter!(xs, ys .- 1, color = xs) +scatter!(xs, ys .- 2, markersize = LinRange(5, 30, 20)) +scatter!(xs, ys .- 3, marker = 'a':'t', strokewidth = 0, color = :black) + +f +save("example_scatter_1.svg", f); nothing # hide +``` + +![example_scatter_1](example_scatter_1.svg) + diff --git a/docs/src/plotting_functions/scatterlines.md b/docs/src/plotting_functions/scatterlines.md new file mode 100644 index 000000000..15834d7aa --- /dev/null +++ b/docs/src/plotting_functions/scatterlines.md @@ -0,0 +1,31 @@ +# scatterlines + +```@docs +scatterlines +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = LinRange(0, 10, 20) +ys = 0.5 .* sin.(xs) + +scatterlines!(xs, ys, color = :red) +scatterlines!(xs, ys .- 1, color = xs, markercolor = :red) +scatterlines!(xs, ys .- 2, markersize = LinRange(5, 30, 20)) +scatterlines!(xs, ys .- 3, marker = :cross, strokewidth = 0, + strokecolor = :red, markercolor = :orange) + +f +save("example_scatterlines_1.svg", f); nothing # hide +``` + +![example_scatterlines_1](example_scatterlines_1.svg) + diff --git a/docs/src/plotting_functions/stem.md b/docs/src/plotting_functions/stem.md new file mode 100644 index 000000000..7f313ec54 --- /dev/null +++ b/docs/src/plotting_functions/stem.md @@ -0,0 +1,92 @@ +# stem + +```@docs +stem +``` + +### Examples + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = LinRange(0, 4pi, 30) + +stem!(xs, sin.(xs)) + +f +save("example_stem_1.svg", f); nothing # hide +``` + +![example stem_1](example_stem_1.svg) + + + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = LinRange(0, 4pi, 30) + +stem!(xs, sin, + offset = 0.5, trunkcolor = :blue, marker = :rect, + stemcolor = :red, color = :orange, + markersize = 15, strokecolor = :red, strokewidth = 3, + trunklinestyle = :dash, stemlinestyle = :dashdot) + +f +save("example_stem_2.svg", f); nothing # hide +``` + +![example stem_2](example_stem_2.svg) + + + +```@example +using CairoMakie +CairoMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) +Axis(f[1, 1]) + +xs = LinRange(0, 4pi, 30) + +stem!(xs, sin.(xs), + offset = LinRange(-0.5, 0.5, 30), + color = LinRange(0, 1, 30), colorrange = (0, 0.5), + trunkcolor = LinRange(0, 1, 30), trunkwidth = 5) + +f +save("example_stem_3.svg", f); nothing # hide +``` + +![example stem_3](example_stem_3.svg) + + + +```@example +using GLMakie +GLMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +f = Figure(resolution = (800, 600)) + +xs = LinRange(0, 4pi, 30) + +stem(f[1, 1], 0.5xs, 2 .* sin.(xs), 2 .* cos.(xs), + offset = Point3f0.(0.5xs, sin.(xs), cos.(xs)), + stemcolor = LinRange(0, 1, 30), stemcolormap = :Spectral, stemcolorrange = (0, 0.5)) + +f +``` + + diff --git a/docs/src/plotting_functions/surface.md b/docs/src/plotting_functions/surface.md new file mode 100644 index 000000000..6a1bb77fc --- /dev/null +++ b/docs/src/plotting_functions/surface.md @@ -0,0 +1,20 @@ +# surface + +```@docs +surface +``` + +### Examples + +```@example +using GLMakie +GLMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +xs = LinRange(0, 10, 100) +ys = LinRange(0, 15, 100) +zs = [cos(x) * sin(y) for x in xs, y in ys] + +surface(xs, ys, zs) +``` + diff --git a/docs/src/plotting_functions/text.md b/docs/src/plotting_functions/text.md new file mode 100644 index 000000000..938a545b9 --- /dev/null +++ b/docs/src/plotting_functions/text.md @@ -0,0 +1,27 @@ +# text + +```@docs +text +``` + +### Examples + +```@example +using GLMakie +GLMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +scene = Scene(camera = campixel!, show_axis = false, resolution = (600, 600)) + +text!(scene, "AbstractPlotting", position = Point2f0(300, 500), + textsize = 30, align = (:left, :bottom), show_axis = false) +text!(scene, "AbstractPlotting", position = Point2f0(300, 400), + color = :red, textsize = 30, align = (:right, :center), show_axis = false) +text!(scene, "AbstractPlotting\nMakie", position = Point2f0(300, 300), + color = :blue, textsize = 30, align = (:center, :center), show_axis = false) +text!(scene, "AbstractPlotting\nMakie", position = Point2f0(300, 200), + color = :green, textsize = 30, align = (:center, :top), rotation = pi/4, show_axis = false) + +scene +``` + diff --git a/docs/src/plotting_functions/volume.md b/docs/src/plotting_functions/volume.md new file mode 100644 index 000000000..0da7bc093 --- /dev/null +++ b/docs/src/plotting_functions/volume.md @@ -0,0 +1,19 @@ +# volume + +```@docs +volume +``` + +### Examples + +```@example +using GLMakie +GLMakie.activate!() # hide +AbstractPlotting.inline!(true) # hide + +r = LinRange(-1, 1, 100) +cube = [(x.^2 + y.^2 + z.^2) for x = r, y = r, z = r] +cube_with_holes = cube .* (cube .> 1.4) + +volume(cube_with_holes, algorithm = :iso, isorange = 0.05, isovalue = 1.7) +```