Repository navigation
Expand file tree
/
Copy pathusing-reticulate.R
More file actions
73 lines (52 loc) · 1.69 KB
/
Copy pathusing-reticulate.R
File metadata and controls
73 lines (52 loc) · 1.69 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
############################################
# Data Professor #
# http://youtube.com/dataprofessor #
# http://github.com/dataprofessor #
# http://facebook.com/dataprofessor #
# https://www.instagram.com/data.professor #
############################################
# https://rstudio.github.io/reticulate/
# install.packages("reticulate")
library(reticulate)
# Loads Python Shell
repl_python()
# Check the current Python version
reticulate::py_config()
# Load a particular Python version on our system
use_python("C:/Program Files/Python38", required = TRUE)
############################
#
# matplotlib Example - Scatter plot
# https://matplotlib.org/3.1.1/gallery/shapes_and_collections/scatter.html#sphx-glr-gallery-shapes-and-collections-scatter-py
#
############################
############################
# Import libraries
############################
# import matplotlib.pyplot as plt
plt <- import('matplotlib.pyplot')
# import numpy as np
np <- import('numpy')
############################
# Load the Iris dataset
############################
data(iris)
############################
# Fixing random state for reproducibility
############################
# np.random.seed(19680801) # https://github.com/rstudio/reticulate/issues/226
np$random$seed(19680801L)
# N = 50
N <- 50L
# x = np.random.rand(N)
x <- np$random$rand(N)
# y = np.random.rand(N)
y <- np$random$rand(N)
# colors = np.random.rand(N)
colors <- np$random$rand(N)
# area = (30 * np.random.rand(N))**2 # 0 to 15 point radii
area <- (30 * np$random$rand(N))**2
# plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt$scatter(x, y, s=area, c=colors, alpha=0.5)
# plt.show()
plt$show()