Skip to content

Commit 3b882be

Browse files
committed
Added fit line using numpy.polyfit function.
1 parent dfe0e63 commit 3b882be

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

scripts/make_performance_scatter_plots.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import matplotlib.pyplot as plt
55
import matplotlib.lines as mlines
6+
import numpy
67
import random
78

89

@@ -56,6 +57,8 @@ def make_scatter_plot(
5657
faxis_name=None,
5758
xaxis_log=False,
5859
faxis_log=False,
60+
draw_diagonal=False,
61+
draw_fitline=False,
5962
size_xy=None,
6063
dpi=None
6164
):
@@ -79,17 +82,27 @@ def make_scatter_plot(
7982
if xaxis_log:
8083
ax.set_xscale('log')
8184
if faxis_log:
82-
ax.set_yscale('log')
85+
ax.set_yscale('symlog')
8386
ax.grid(True, linestyle='dotted')
8487
xs = []
8588
ys = []
8689
for x, y in points:
8790
xs.append(x)
8891
ys.append(y)
8992
ax.scatter(xs, ys)
90-
line = mlines.Line2D([0, 1], [0, 1], color="red")
91-
line.set_transform(ax.transAxes)
92-
ax.add_line(line)
93+
if draw_diagonal:
94+
line = mlines.Line2D([0, 1], [0, 1], color=("blue" if draw_fitline else "red"))
95+
line.set_transform(ax.transAxes)
96+
ax.add_line(line)
97+
if draw_fitline:
98+
line_coefs = numpy.polyfit(xs, ys, 1)
99+
x_lo = min(xs)
100+
x_hi = max(xs)
101+
n_steps = 1000
102+
dx = (x_hi - x_lo) / n_steps
103+
lxs = sorted(xs + [x_lo + t * dx for t in range(n_steps + 1)])
104+
lys = [line_coefs[0] * x + line_coefs[1] for x in lxs]
105+
ax.plot(lxs, lys, "r-")
93106
fig.savefig(pathname, bbox_inches='tight', format=format)
94107

95108

@@ -113,6 +126,7 @@ def _main(cmdline):
113126
"goto-program locations",
114127
"seconds",
115128
True,
129+
True,
116130
True
117131
)
118132
make_scatter_plot(
@@ -123,6 +137,7 @@ def _main(cmdline):
123137
"goto-program locations",
124138
"MB",
125139
True,
140+
True,
126141
True
127142
)
128143

0 commit comments

Comments
 (0)