forked from binder-examples/r_with_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
python_example_for_RStudio.Rmd
61 lines (51 loc) · 1.08 KB
/
python_example_for_RStudio.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
title: "Example"
subtitle: "SUBTITLE"
author: "AUTHORS"
output:
html_document:
df_print: paged
number_sections: yes
toc: yes
toc_float: true
toc_depth: 3
code_folding: show
editor_options:
chunk_output_type: inline
---
# $\LaTeX$ Math
This is just markdown that can include latex math.
$$
\begin{align}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
\dot{z} & = -\beta z + xy
\end{align}
$$
# System Info
```{python}
import IPython
print(IPython.sys_info())
```
# Data
```{python}
import pandas as pd
import numpy as np
curve = pd.DataFrame(np.arange(0.0, 2.0, 0.01), columns=list('t'))
curve['x'] = 1 + np.sin(2 * np.pi * curve['t'])
```
```{r}
# access python variable via reticulate - requires RStudio 1.2+ to work interactively
library(reticulate)
py$curve
```
# Plot
```{r, fig.width=8, fig.height=4}
# python plots (e.g. matplotlib) require RStudio 1.2+ for proper rendering
# using reticulate and ggplot instead (will work only in knitted document)
library(ggplot2)
ggplot(py$curve) +
aes(x = t, y = x) +
geom_line() +
theme_bw()
```