Engee 文档

主题

该页面正在翻译中。

Makie允许您通过属性更改绘图的几乎每个视觉方面。 您可以在创建对象时设置属性,也可以定义一个常规样式,然后由以下所有对象用作默认样式。

有三个函数可以用于此目的:

set_theme!
update_theme!
with_theme

还有 预定义的主题,可能形成一个有用的起点。

set_theme!

你可以打电话 set_theme!(主题;kwargs。..) 将当前默认主题更改为 主题 并复盖或添加由 夸格斯. 您也可以通过调用重置更改 set_theme!() 没有争论。

让我们用默认主题创建一个情节: </无翻译>

using CairoMakie
function example_plot()
    f = Figure()
    for i in 1:2, j in 1:2
        lines(f[i, j], cumsum(randn(50)))
    end
    Label(f[0, :], "A simple example plot")
    Label(f[3, :], L"Random walks $x(t_n)$")
    f
end

example_plot()
d02e63b

现在我们定义一个主题,它改变了默认的字体大小,激活它,并绘制。 </无翻译>

fontsize_theme = Theme(fontsize = 10)
set_theme!(fontsize_theme)

example_plot()
2ec172e

这个主题将是活跃的,直到我们打电话 set_theme!().

set_theme!()

合并;合并

主题通常只影响部分情节属性。 因此,可以将主题组合在一起以获得各自的效果。

例如,您可以将深色主题与LaTeX fonts主题相结合,以同时具有深色和统一字体。 </无翻译>

dark_latexfonts = merge(theme_dark(), theme_latexfonts())
with_theme(dark_latexfonts) do
    example_plot()
end
7b45468

update_theme!

如果您已经激活了一个主题,并且想部分更新它,而不删除新主题中没有的属性,您可以使用 update_theme!.

例如,您可以决定在激活上一节中的dark和latex主题后更改文本大小。 </无翻译>

update_theme!(fontsize=30)
example_plot()
4c5fed9

with_主题

因为记住把你只需要暂时关闭的主题关掉会很乏味,所以有一个功能 with_theme(f,主题) 它会自动为您处理重置,即使您在运行时遇到错误 f. </无翻译>

with_theme(fontsize_theme) do
    example_plot()
end
1d8e81c

您还可以传递其他关键字以在模版中添加或复盖属性: </无翻译>

with_theme(fontsize_theme, fontsize = 25) do
    example_plot()
end
88d02bb

主题绘制对象

您可以将对象的大写类型名称用作模版中的键来对其进行模版绘制。 </无翻译>

lines_theme = Theme(
    Lines = (
        linewidth = 4,
        linestyle = :dash,
    )
)

with_theme(example_plot, lines_theme)
2b8e645

主题块对象

每个街区,如 轴心,轴心, 传说, 颜色栏 等。 可以通过使用其类型名称作为主题中的键来主题。

以下是如何为轴定义一个简单的类似ggplot的样式: </无翻译>

ggplot_theme = Theme(
    Axis = (
        backgroundcolor = :gray90,
        leftspinevisible = false,
        rightspinevisible = false,
        bottomspinevisible = false,
        topspinevisible = false,
        xgridcolor = :white,
        ygridcolor = :white,
    )
)

with_theme(example_plot, ggplot_theme)
5eb7d40

周期

Makie支持自动循环情节属性的多种选项。 对于要使用循环的情节对象,其默认主题或当前活动主题必须具有 周期 属性集。

有多种方法可以指定此属性:

# You can either make a list of symbols
cycle = [:color, :marker]
# or map specific plot attributes to palette attributes
cycle = [:linecolor => :color, :marker]
# you can also map multiple attributes that should receive
# the same cycle attribute
cycle = [[:linecolor, :markercolor] => :color, :marker]
# nothing disables cycling
cycle = nothing # equivalent to cycle = []

请注意,周期必须作为情节对象的属性而不是顶级主题(因为不同的情节对象可以循环不同的属性,例如,密度图不能循环标记)。 下面的代码块举例说明了这一点。 </无翻译>

with_theme(
    Theme(
        palette = (color = [:red, :blue], marker = [:circle, :xcross]),
        Scatter = (cycle = [:color, :marker],)
    )) do
    scatter(fill(1, 10))
    scatter!(fill(2, 10))
    scatter!(fill(3, 10))
    scatter!(fill(4, 10))
    scatter!(fill(5, 10))
    current_figure()
end
5376e4b

协变周期

你也可以构造一个 周期 对象直接,这另外允许设置 科瓦里 关键字,默认为 错误. 一个骑自行车的人 covary=真 将所有属性循环在一起,而不是循环遍历第一个,然后是第二个等的所有值。

# palettes: color = [:red, :blue, :green] marker = [:circle, :rect, :utriangle, :dtriangle]

cycle = [:color, :marker]
# 1: :red, :circle
# 2: :blue, :circle
# 3: :green, :circle
# 4: :red, :rect
# ...

cycle = Cycle([:color, :marker], covary = true)
# 1: :red, :circle
# 2: :blue, :rect
# 3: :green, :utriangle
# 4: :red, :dtriangle
# ...

例如 </无翻译>

with_theme(
    Theme(
        palette = (color = [:red, :blue], linestyle = [:dash, :dot]),
        Lines = (cycle = Cycle([:color, :linestyle], covary = true),)
    )) do
    lines(fill(5, 10))
    lines!(fill(4, 10))
    lines!(fill(3, 10))
    lines!(fill(2, 10))
    lines!(fill(1, 10))
    current_figure()
end
9005d50

使用手动循环 骑自行车

如果你想给一个图的属性一个特定的值从各自的循环器,你可以使用 骑自行车 对象。 索引 i 传递给 循环 直接用于在循环器中查找属于该属性的值,如果没有定义这样的循环器,则出错。 例如,要访问循环仪中的第三种颜色,而不是绘制三个图以推进循环仪,您可以使用 颜色=循环(3).

循环器的内部计数器在使用时不先进 骑自行车 对于任何属性,并且仅具有 骑自行车 访问循环的值,所有其他通常循环的属性都回退到其非循环的默认值。 </无翻译>

using CairoMakie
f = Figure()

Axis(f[1, 1])

# the normal cycle
lines!(0..10, x -> sin(x) - 1)
lines!(0..10, x -> sin(x) - 2)
lines!(0..10, x -> sin(x) - 3)

# manually specified colors
lines!(0..10, x -> sin(x) - 5, color = Cycled(3))
lines!(0..10, x -> sin(x) - 6, color = Cycled(2))
lines!(0..10, x -> sin(x) - 7, color = Cycled(1))

f
a0090c5

调色板

循环中指定的属性在轴的调色板中查找。 一个单 :颜色 既是plot属性又是palette属性,而 :颜色=>:patchcolor 意思是 情节。颜色 应设置为 调色板。贴片色,贴片色. 下面的示例显示了密度图对不同调色板选项的反应: </无翻译>

using CairoMakie

f = Figure(size = (800, 800))

Axis(f[1, 1], title = "Default cycle palette")

for i in 1:6
    density!(randn(50) .+ 2i)
end

Axis(f[2, 1],
    title = "Custom cycle palette",
    palette = (patchcolor = [:red, :green, :blue, :yellow, :orange, :pink],))

for i in 1:6
    density!(randn(50) .+ 2i)
end

set_theme!(Density = (cycle = [],))

Axis(f[3, 1], title = "No cycle")

for i in 1:6
    density!(randn(50) .+ 2i)
end


f
c619415

你也可以通过 set_theme!(调色板=(颜色=my_colors,标记=my_markers)) 例如。

特殊属性

你可以用钥匙 rowgap,rowgap科尔加普 要更改默认网格布局间隙。