%matplotlib内联在Rmarkdown / R笔记本中

时间:2018-02-07 22:05:54

标签: python r matplotlib jupyter-notebook r-markdown

上下文:我正在对Jupyter笔记本和R笔记本进行一些比较。我喜欢R笔记本的一件事是你可以改变单元格之间的语言。我正在使用以下已发布的笔记本https://bitaesthetics.com/posts/fractal-generation-with-l-systems.html

对此进行测试

问题:在线绘制python结果似乎不起作用。我可以致电plt.show(),然后弹出图表,但%matplotlib inline会产生以下错误:

File "/var/folders/30/dl1nh_s15mq9j9b0469q_vvh0000gn/T/RtmpjAYRiE/chunk-code22c26a73f799.", line 1
    %matplotlib inline
    ^
SyntaxError: invalid syntax

可重复示例:

```{python}
    %matplotlib inline
    import matplotlib.pyplot as plt
    plt.style.use('bmh')  # Use some nicer default colors
    plt.plot(
        [0, 1, 2],  # X-values
        [0, 1, 0]   # Y-values
    )
    # The next two lines add labels to the axes.
    plt.xlabel('x')
    plt.ylabel('y');
```

任何人都有这方面的经验吗?我查看了Rstudio帮助页面和GitHub,发现他们正在开发一个新的软件包,网格,https://github.com/rstudio/reticulate/pull/107#issuecomment-359944469,而不是在R markdown中为本机python提供大量支持。

谢谢!

0 个答案:

没有答案