Repository navigation
Expand file tree
/
Copy pathrandomgraph
More file actions
executable file
·84 lines (70 loc) · 1.73 KB
/
Copy pathrandomgraph
File metadata and controls
executable file
·84 lines (70 loc) · 1.73 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
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python3
import argparse
import random
import plotly.express as px
COLORBG = "#fff5e6"
COLORDOT = "#ff9700"
COLORPAPER = "#fafafa"
# to get the same output on mutliple runs
random.seed(1)
ap = argparse.ArgumentParser()
ap.add_argument("--noshow", action="store_true")
ap.add_argument("--png")
ap.add_argument("--svg")
ap.add_argument("--html")
ap.add_argument("--divid", default="plot1")
args = ap.parse_args()
mdat = []
x = []
y = []
for _ in range(500):
v = {}
v["x"] = random.randint(1, 1000000)
v["y"] = random.randint(1, 1000000)
v["size"] = random.randint(1, 1000)
mdat.append(v)
x.append(v["x"])
y.append(v["y"])
try:
import scipy
linre = scipy.stats.linregress(x, y)
print("r : " + str(linre.rvalue))
print("R^2 : " + str(linre.rvalue**2))
except ImportError:
print("scipy not available, cannot calculate r (correlation coefficient)")
fig = px.scatter(
mdat,
x="x",
y="y",
size="size",
size_max=15,
log_x=True,
log_y=True,
width=640,
height=360,
color_discrete_sequence=[COLORDOT],
)
fig.update_layout(
plot_bgcolor=COLORBG,
paper_bgcolor=COLORPAPER,
margin={"l": 0, "r": 0, "b": 0, "t": 0},
font={"family": "Roboto,Helvetica,Sans-Serif", "weight": "bold"},
xaxis_title="Random data",
yaxis_title="Random data",
)
fig.update_xaxes(gridcolor="lightgrey", rangemode="tozero")
fig.update_yaxes(gridcolor="lightgrey", rangemode="tozero")
if not args.noshow:
fig.show()
if args.png:
fig.write_image(args.png)
if args.svg:
fig.write_image(args.svg)
if args.html:
fig.write_html(
args.html,
include_plotlyjs=False,
include_mathjax=False,
full_html=False,
div_id=args.divid,
)