3
3
import json
4
4
import matplotlib .pyplot as plt
5
5
import matplotlib .lines as mlines
6
+ import numpy
6
7
import random
7
8
8
9
@@ -56,6 +57,8 @@ def make_scatter_plot(
56
57
faxis_name = None ,
57
58
xaxis_log = False ,
58
59
faxis_log = False ,
60
+ draw_diagonal = False ,
61
+ draw_fitline = False ,
59
62
size_xy = None ,
60
63
dpi = None
61
64
):
@@ -79,17 +82,27 @@ def make_scatter_plot(
79
82
if xaxis_log :
80
83
ax .set_xscale ('log' )
81
84
if faxis_log :
82
- ax .set_yscale ('log ' )
85
+ ax .set_yscale ('symlog ' )
83
86
ax .grid (True , linestyle = 'dotted' )
84
87
xs = []
85
88
ys = []
86
89
for x , y in points :
87
90
xs .append (x )
88
91
ys .append (y )
89
92
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-" )
93
106
fig .savefig (pathname , bbox_inches = 'tight' , format = format )
94
107
95
108
@@ -113,6 +126,7 @@ def _main(cmdline):
113
126
"goto-program locations" ,
114
127
"seconds" ,
115
128
True ,
129
+ True ,
116
130
True
117
131
)
118
132
make_scatter_plot (
@@ -123,6 +137,7 @@ def _main(cmdline):
123
137
"goto-program locations" ,
124
138
"MB" ,
125
139
True ,
140
+ True ,
126
141
True
127
142
)
128
143
0 commit comments