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

第3章第9节第2小节 梯度下降算法的过程演示图存在错误 #3

Closed
XiangyunHuang opened this issue Aug 15, 2019 · 5 comments
Labels
question Further information is requested

Comments

@XiangyunHuang
Copy link
Owner

demo("gradArrows1", package = "MSG")

图的 title 公式显示不对 @yihui

grad

@yihui
Copy link
Collaborator

yihui commented Aug 15, 2019

原稿中我基本全是用 dev = 'tikz' 生成的 PDF 图形。如果要考虑非 PDF 输出的话,这问题会有点复杂。需要先生成 PDF 再转 PNG。其实在 R Markdown 中用 dev = 'tikz' 就已经够复杂了,里面涉及到一些 tikzDevice 包的选项配置,尤其是图中包含中文时。这些配置可能世界上只有一两个人明白……

如果不是为了图形中的字体漂亮的话,也可以放弃 tikz 图形设备,改用基础图形系统中丑陋的 plotmath 办法,也就是用 expression() 写数学公式。

@XiangyunHuang
Copy link
Owner Author

@yihui 明白了,我准备引入 magick 包将自动生成的 PDF 图片转 PNG 图片

# convert pdf to png
to_png <- function(fig_path) {
  png_path <- sub("\\.pdf$", ".png", fig_path)
  magick::image_write(magick::image_read_pdf(fig_path), format = "png", path = png_path)
  return(png_path)
}

生成这类图形的代码块选项添加 dev='tikz',fig.process=to_png,如果再遇到中文,我就写一个自定义的 tikz 的模板,而不是调默认的模板

@XiangyunHuang XiangyunHuang added the question Further information is requested label Aug 18, 2019
@pzhaonet
Copy link
Collaborator

pzhaonet commented Aug 7, 2020

目前的 pdf 书稿里,有一部分图不是 tikz。我想尽可能全部用 tikz,但是中文支持有问题:为了使用 tikz,我设置 fig.showtext = FALSE,导致图中的中文全显示为空心小方块;如果设置 fig.showtext = TRUE,中文是正常显示了,但 tikz 就失效。这是不是需要 @XiangyunHuang 说的“自定义的 tikz 模板”来解决?

@XiangyunHuang
Copy link
Owner Author

@pzhaonet 是的。要自定义,可以参考这一节 https://masr.netlify.app/chap-data-visualization.html#subsec:tikz-device

@pzhaonet
Copy link
Collaborator

pzhaonet commented Aug 7, 2020

@XiangyunHuang 好的,我试试看成不成。涉及中文的图倒是不太多,不成就忽略了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants