-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
52 lines (45 loc) · 1.42 KB
/
run.py
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
NUM = 18200
def plot_rust():
from pyo3_plotters import plot_with_plotters
plot_with_plotters("a.png", [p/1000 for p in range(-NUM, NUM)])
def plot_matplotlib():
import math
import matplotlib
matplotlib.use("agg")
import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(10.24, 7.68))
fig.suptitle("Image Title")
x = [p/1000 for p in range(-NUM, NUM)]
y = [math.sin(p/1000) for p in range(-NUM, NUM)]
axes[0].plot(x, y, label="Sine")
axes[0].legend()
axes[1].plot(x, y, label="Sine")
axes[1].legend()
plt.savefig("b.png")
plt.clf()
plt.close(fig)
def plot_plotly():
import math
import plotly.express as px
from kaleido.scopes.plotly import PlotlyScope
scope = PlotlyScope(
plotlyjs="https://cdn.plot.ly/plotly-latest.min.js",
# plotlyjs="/path/to/local/plotly.js",
)
x = [p/1000 for p in range(-NUM, NUM)]
y = [math.sin(p/1000) for p in range(-NUM, NUM)]
fig = px.line({'x': x, 'y': y})
with open("c.png", "wb") as f:
f.write(scope.transform(fig, format="png"))
def main():
plot_rust()
plot_matplotlib()
# plot_plotly()
if __name__ == '__main__':
from line_profiler import LineProfiler
prof = LineProfiler()
prof.add_function(plot_rust)
prof.add_function(plot_matplotlib)
prof.add_function(plot_plotly)
prof.runcall(main)
prof.print_stats(output_unit=1e-3)