Julia绘图并保存MSWord支持的格式


安装 Inkscape

从Inkscape 官网 https://inkscape.org 下载安装。 将安装目录下的bin文件加添加到PATH环境变量,默认为C:\Program Files\Inkscape\bin

Julia 示例代码

采用Plots.jl包绘图并在文字中支持LaTeX字符串

# 自行安装 Plots 及 LaTeXStrings 这两个包
using Plots
using LaTeXStrings
x = -1:0.1:1
p = plot(x->1/(1+x^2), x,
  title=L"Plot of $\frac{1}{1+x^2}$",
  xlabel=L"$x$",
  ylabel=L"$y$",
  label=false)

保存图片并使用InkScape转换格式

转换为矢量格式

savefig(p, "test.pdf")
run(`inkscape --pdf-poppler --export-type=emf test.pdf`)
# 输出 test.emf 即可插入word
# inkscape --help 可以查看使用帮助

当然也可以转换为位图

run(`inkscape --pdf-poppler --export-type=png -w 800 test.pdf`)
# -w 指定宽度(单位为像素) 也可以用 -h 指定高度
# 同时指定 -w -h 会拉伸图像
# 曲线尽量采用矢量图格式,否则DPI至少600,约240像素/厘米
# 对于云图推荐DPI 300以上, 约120像素/厘米
CC BY-SA 4.0 LETIX.INFO. Last modified: Jun 03, 2023.
Built with Franklin.jl and the Julia programming language.