MakiePublication.jl 教程:打造专业学术图表

MakiePublication.jl 教程:打造专业学术图表

MakiePublication.jl A Julia package for producing publication quality figures based on Makie.jl. MakiePublication.jl 项目地址: https://gitcode.com/gh_mirrors/ma/MakiePublication.jl

引言

在学术研究和论文写作中,高质量的图表展示是传达研究成果的重要方式。MakiePublication.jl 是一个基于 Julia 语言的绘图工具包,专为学术出版设计,能够生成符合期刊出版标准的矢量图形。本文将详细介绍如何使用 MakiePublication.jl 创建专业级图表。

基础配置

要使用 MakiePublication,首先需要导入必要的包:

using MakiePublication
using CairoMakie

选择 CairoMakie 作为后端是因为它支持生成 PDF、EPS 和 SVG 等矢量图形格式,这些格式是学术期刊出版的首选。

基础绘图示例

最简单的绘图方式是使用 with_theme 代码块:

with_theme(theme_web()) do
    lines(0..10, sin)
    lines!(0..10, cos)
    current_figure()
end

这个例子展示了如何在同一坐标系中绘制正弦和余弦曲线。MakiePublication 提供了多种预设主题,theme_web() 是其中之一,它针对网页显示做了优化。

复杂图表绘制

对于更复杂的图表,可以将绘图逻辑封装为函数,并通过 with_theme 应用主题:

function myplot(; figure_padding=(2,6,1,6), legend_margin=((5,0,0,0)))
    # 绘图逻辑...
end

这个示例函数展示了:

  1. 如何同时绘制拟合线和数据点
  2. 自定义图例位置、边距和列数
  3. 调整画布边距
  4. 设置坐标轴范围

主题定制

MakiePublication 提供了丰富的主题定制选项:

颜色方案

内置了15种颜色方案,存储在 MakiePublication.COLORS 数组中:

with_theme(myplot_web, theme_web(colors=MakiePublication.COLORS[5]))

也可以通过函数获取特定颜色方案:

with_theme(myplot_web, theme_web(colors=MakiePublication.tol_bright()))

线型设置

默认线型存储在 MakiePublication.LINESTYLES 中,可以通过 linestyles 参数覆盖:

lc = Cycle([:color, :linestyle], covary=true)
with_theme(myplot_web, theme_web(linecycle=lc, linestyles=[nothing, :dash]))

标记样式

标记样式存储在 MakiePublication.MARKERS 中,可通过 markers 参数自定义:

with_theme(myplot_web, theme_web(markers=[:circle, :diamond]))

空心标记

创建空心标记需要明确定义标记循环:

sc = Cycle([:color=>:markercolor, :strokecolor=>:color], covary=true)
with_theme(myplot_web, 
    theme_web(scattercycle=sc, 
             ishollowmarkers=[false, true], 
             markerstrokewidth=1.5))

循环器高级用法

循环器(Cycler)是 MakiePublication 的强大功能,可以实现复杂的样式循环:

lc = Cycle([:color, :linestyle], covary=true)
sc = Cycle([:color=>:markercolor, :strokecolor=>:color, :marker], covary=true)
with_theme(myplot_web,
    theme_web(
        colors=MakiePublication.tableau_10(),
        linestyles=[nothing, :dash, :dash],
        ishollowmarkers=[false, true, false],
        markers=[:circle, :diamond, :rtriangle],
        linecycle=lc,
        scattercycle=sc,
        markerstrokewidth=1.5)
)

图表导出

MakiePublication 提供两种导出图表的方式:

  1. 使用 savefig 函数:
fig = with_theme(myplot, theme_acs())
savefig("plot.svg", fig)
  1. 使用 save 函数,可自定义分辨率:
fig_web = with_theme(myplot_web, theme_web())
save("plot_web.png", fig_web, px_per_unit=4)

结语

MakiePublication.jl 为学术图表制作提供了专业级的解决方案。通过本教程介绍的各种功能和技巧,用户可以轻松创建符合学术出版标准的高质量图表。无论是简单的曲线图还是复杂的多元素图表,MakiePublication 都能满足您的需求。

MakiePublication.jl A Julia package for producing publication quality figures based on Makie.jl. MakiePublication.jl 项目地址: https://gitcode.com/gh_mirrors/ma/MakiePublication.jl

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孙典将Phyllis

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值