Skip to content

Commit 2d788c3

Browse files
committed
Implement scale function flag
Add a flag to allow the user to specify the scaling function to use for scaling the dataset in order to the user more control over the resulitng plot. Especially in the case that they want to plot 3D locational data. Closes #2
1 parent 6f2b0d3 commit 2d788c3

9 files changed

+495
-10
lines changed

blendplot/__main__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def blendplot(app):
2828
spacing = app.params.spacing
2929
point_size = app.params.pointsize
3030
category_column = app.params.category
31+
scale_function = app.params.scale_function
3132

32-
main(input_filename, output_filename, num_rows, columns, spacing, point_size, category_column)
33+
main(input_filename, output_filename, num_rows, columns, spacing, point_size, category_column, scale_function)
3334

3435
blendplot.add_param("input_file", help="data file to plot", type=str)
3536
blendplot.add_param("output_file", help="obj file to output to", type=str)
@@ -41,8 +42,9 @@ def blendplot(app):
4142
blendplot.add_param("--spacing", help="the scaling factor to space the data out by", default=2.0, type=float)
4243
blendplot.add_param("--pointsize", help="the size to use for the data points", default=0.0625, type=float)
4344
blendplot.add_param("-c", "--category", help="the column to use for point categorization", default=None, type=str)
45+
blendplot.add_param("--scale-function", help="the function to use for scaling the data, valid options are \"maxabs_scale\", \"minmax_scale\", \"normalize\", \"robust_scale\", \"scale\", and \"none\"", default="scale", type=str)
4446

45-
def main(input_filename, output_filename, num_rows, columns, spacing, point_size, category_column):
47+
def main(input_filename, output_filename, num_rows, columns, spacing, point_size, category_column, scale_function):
4648
"""
4749
Plots the data in the given input file to the given output file with the
4850
specified settings.
@@ -64,10 +66,20 @@ def main(input_filename, output_filename, num_rows, columns, spacing, point_size
6466
category_column : str
6567
the column to categorize the points by, or None to plot data without
6668
categories
69+
scale_function : str
70+
the name of the data scaling function to use
6771
"""
72+
valid_scale_functions = ["maxabs_scale", "minmax_scale", "normalize", "robust_scale", "scale", "none"]
73+
if not scale_function in valid_scale_functions:
74+
print("Invalid scale-function: %s" % scale_function, file=sys.stderr)
75+
76+
valid_function_list = ", ".join(valid_scale_functions)
77+
print("Valid scale-functions are: %s" % valid_function_list, file=sys.stderr)
78+
sys.exit(1)
79+
6880
output_file = open(output_filename, "w")
6981
start = time.time()
70-
points = obj_graph.plot_file(input_filename, output_file, num_rows, columns, spacing, point_size, category_column)
82+
points = obj_graph.plot_file(input_filename, output_file, num_rows, columns, spacing, point_size, category_column, scale_function)
7183
end = time.time()
7284
output_file.close()
7385

blendplot/obj_graph.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def plot(rows, spacing, point_size, output_file, start_num):
145145

146146
return start_num
147147

148-
def plot_file(input_filename, output_file, num_rows, columns, spacing, point_size, category_column):
148+
def plot_file(input_filename, output_file, num_rows, columns, spacing, point_size, category_column, scale_function):
149149
"""
150150
Plots the data from the given input file to the given output file and
151151
returns the number of points plotted.
@@ -167,6 +167,8 @@ def plot_file(input_filename, output_file, num_rows, columns, spacing, point_siz
167167
category_column : str
168168
the column to categorize the points by, or None to plot data without
169169
categories
170+
scale_function : str
171+
the name of the data scaling function to use
170172
171173
Returns
172174
-------
@@ -186,7 +188,7 @@ def plot_file(input_filename, output_file, num_rows, columns, spacing, point_siz
186188
return None
187189

188190
data = pd.DataFrame(original_data, columns = columns).dropna()
189-
data = pd.DataFrame(preprocessing.scale(data), columns = data.columns)
191+
data = pd.DataFrame(scale_data(data, scale_function), columns = data.columns)
190192

191193
start_num = 0
192194

@@ -237,3 +239,18 @@ def get_missing_columns(data, columns, category_column):
237239
missing.append(col)
238240

239241
return missing
242+
243+
def scale_data(original_data, scale_name):
244+
scale_functions = {
245+
"maxabs_scale": preprocessing.maxabs_scale,
246+
"minmax_scale": preprocessing.minmax_scale,
247+
"normalize": preprocessing.normalize,
248+
"robust_scale": preprocessing.robust_scale,
249+
"scale": preprocessing.scale,
250+
"none": lambda x: x
251+
}
252+
253+
function = scale_functions[scale_name]
254+
scaled_data = function(original_data)
255+
256+
return scaled_data
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
o data
2+
v 0.225 0.119298245614 0.241726618705
3+
v 0.225 0.119298245614 0.441726618705
4+
v 0.025 0.119298245614 0.441726618705
5+
v 0.025 0.119298245614 0.241726618705
6+
v 0.225 0.319298245614 0.241726618705
7+
v 0.225 0.319298245614 0.441726618705
8+
v 0.025 0.319298245614 0.441726618705
9+
v 0.025 0.319298245614 0.241726618705
10+
f 1 2 3 4
11+
f 5 8 7 6
12+
f 1 5 6 2
13+
f 2 6 7 3
14+
f 3 7 8 4
15+
f 5 1 4 8
16+
v 0.25 0.233333333333 0.313669064748
17+
v 0.25 0.233333333333 0.513669064748
18+
v 0.05 0.233333333333 0.513669064748
19+
v 0.05 0.233333333333 0.313669064748
20+
v 0.25 0.433333333333 0.313669064748
21+
v 0.25 0.433333333333 0.513669064748
22+
v 0.05 0.433333333333 0.513669064748
23+
v 0.05 0.433333333333 0.313669064748
24+
f 9 10 11 12
25+
f 13 16 15 14
26+
f 9 13 14 10
27+
f 10 14 15 11
28+
f 11 15 16 12
29+
f 13 9 12 16
30+
v 0.6 0.382456140351 0.245323741007
31+
v 0.6 0.382456140351 0.445323741007
32+
v 0.4 0.382456140351 0.445323741007
33+
v 0.4 0.382456140351 0.245323741007
34+
v 0.6 0.582456140351 0.245323741007
35+
v 0.6 0.582456140351 0.445323741007
36+
v 0.4 0.582456140351 0.445323741007
37+
v 0.4 0.582456140351 0.245323741007
38+
f 17 18 19 20
39+
f 21 24 23 22
40+
f 17 21 22 18
41+
f 18 22 23 19
42+
f 19 23 24 20
43+
f 21 17 20 24
44+
v -0.05 0.128070175439 0.353237410072
45+
v -0.05 0.128070175439 0.553237410072
46+
v -0.25 0.128070175439 0.553237410072
47+
v -0.25 0.128070175439 0.353237410072
48+
v -0.05 0.328070175439 0.353237410072
49+
v -0.05 0.328070175439 0.553237410072
50+
v -0.25 0.328070175439 0.553237410072
51+
v -0.25 0.328070175439 0.353237410072
52+
f 25 26 27 28
53+
f 29 32 31 30
54+
f 25 29 30 26
55+
f 26 30 31 27
56+
f 27 31 32 28
57+
f 29 25 28 32
58+
v 0.125 0.4 0.4
59+
v 0.125 0.4 0.6
60+
v -0.075 0.4 0.6
61+
v -0.075 0.4 0.4
62+
v 0.125 0.6 0.4
63+
v 0.125 0.6 0.6
64+
v -0.075 0.6 0.6
65+
v -0.075 0.6 0.4
66+
f 33 34 35 36
67+
f 37 40 39 38
68+
f 33 37 38 34
69+
f 34 38 39 35
70+
f 35 39 40 36
71+
f 37 33 36 40
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
o data
2+
v 0.311538461538 -0.1 -0.1
3+
v 0.311538461538 -0.1 0.1
4+
v 0.111538461538 -0.1 0.1
5+
v 0.111538461538 -0.1 -0.1
6+
v 0.311538461538 0.1 -0.1
7+
v 0.311538461538 0.1 0.1
8+
v 0.111538461538 0.1 0.1
9+
v 0.111538461538 0.1 -0.1
10+
f 1 2 3 4
11+
f 5 8 7 6
12+
f 1 5 6 2
13+
f 2 6 7 3
14+
f 3 7 8 4
15+
f 5 1 4 8
16+
v 0.330769230769 0.103125 0.127272727273
17+
v 0.330769230769 0.103125 0.327272727273
18+
v 0.130769230769 0.103125 0.327272727273
19+
v 0.130769230769 0.103125 0.127272727273
20+
v 0.330769230769 0.303125 0.127272727273
21+
v 0.330769230769 0.303125 0.327272727273
22+
v 0.130769230769 0.303125 0.327272727273
23+
v 0.130769230769 0.303125 0.127272727273
24+
f 9 10 11 12
25+
f 13 16 15 14
26+
f 9 13 14 10
27+
f 10 14 15 11
28+
f 11 15 16 12
29+
f 13 9 12 16
30+
v 0.6 0.36875 -0.0886363636364
31+
v 0.6 0.36875 0.111363636364
32+
v 0.4 0.36875 0.111363636364
33+
v 0.4 0.36875 -0.0886363636364
34+
v 0.6 0.56875 -0.0886363636364
35+
v 0.6 0.56875 0.111363636364
36+
v 0.4 0.56875 0.111363636364
37+
v 0.4 0.56875 -0.0886363636364
38+
f 17 18 19 20
39+
f 21 24 23 22
40+
f 17 21 22 18
41+
f 18 22 23 19
42+
f 19 23 24 20
43+
f 21 17 20 24
44+
v 0.1 -0.084375 0.252272727273
45+
v 0.1 -0.084375 0.452272727273
46+
v -0.1 -0.084375 0.452272727273
47+
v -0.1 -0.084375 0.252272727273
48+
v 0.1 0.115625 0.252272727273
49+
v 0.1 0.115625 0.452272727273
50+
v -0.1 0.115625 0.452272727273
51+
v -0.1 0.115625 0.252272727273
52+
f 25 26 27 28
53+
f 29 32 31 30
54+
f 25 29 30 26
55+
f 26 30 31 27
56+
f 27 31 32 28
57+
f 29 25 28 32
58+
v 0.234615384615 0.4 0.4
59+
v 0.234615384615 0.4 0.6
60+
v 0.0346153846154 0.4 0.6
61+
v 0.0346153846154 0.4 0.4
62+
v 0.234615384615 0.6 0.4
63+
v 0.234615384615 0.6 0.6
64+
v 0.0346153846154 0.6 0.6
65+
v 0.0346153846154 0.6 0.4
66+
f 33 34 35 36
67+
f 37 40 39 38
68+
f 33 37 38 34
69+
f 34 38 39 35
70+
f 35 39 40 36
71+
f 37 33 36 40
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
o data
2+
v 0.6 1.15 4.65
3+
v 0.6 1.15 4.85
4+
v 0.4 1.15 4.85
5+
v 0.4 1.15 4.65
6+
v 0.6 1.35 4.65
7+
v 0.6 1.35 4.85
8+
v 0.4 1.35 4.85
9+
v 0.4 1.35 4.65
10+
f 1 2 3 4
11+
f 5 8 7 6
12+
f 1 5 6 2
13+
f 2 6 7 3
14+
f 3 7 8 4
15+
f 5 1 4 8
16+
v 0.7 1.8 5.65
17+
v 0.7 1.8 5.85
18+
v 0.5 1.8 5.85
19+
v 0.5 1.8 5.65
20+
v 0.7 2.0 5.65
21+
v 0.7 2.0 5.85
22+
v 0.5 2.0 5.85
23+
v 0.5 2.0 5.65
24+
f 9 10 11 12
25+
f 13 16 15 14
26+
f 9 13 14 10
27+
f 10 14 15 11
28+
f 11 15 16 12
29+
f 13 9 12 16
30+
v 2.1 2.65 4.7
31+
v 2.1 2.65 4.9
32+
v 1.9 2.65 4.9
33+
v 1.9 2.65 4.7
34+
v 2.1 2.85 4.7
35+
v 2.1 2.85 4.9
36+
v 1.9 2.85 4.9
37+
v 1.9 2.85 4.7
38+
f 17 18 19 20
39+
f 21 24 23 22
40+
f 17 21 22 18
41+
f 18 22 23 19
42+
f 19 23 24 20
43+
f 21 17 20 24
44+
v -0.5 1.2 6.2
45+
v -0.5 1.2 6.4
46+
v -0.7 1.2 6.4
47+
v -0.7 1.2 6.2
48+
v -0.5 1.4 6.2
49+
v -0.5 1.4 6.4
50+
v -0.7 1.4 6.4
51+
v -0.7 1.4 6.2
52+
f 25 26 27 28
53+
f 29 32 31 30
54+
f 25 29 30 26
55+
f 26 30 31 27
56+
f 27 31 32 28
57+
f 29 25 28 32
58+
v 0.2 2.75 6.85
59+
v 0.2 2.75 7.05
60+
v 0.0 2.75 7.05
61+
v 0.0 2.75 6.85
62+
v 0.2 2.95 6.85
63+
v 0.2 2.95 7.05
64+
v 0.0 2.95 7.05
65+
v 0.0 2.95 6.85
66+
f 33 34 35 36
67+
f 37 40 39 38
68+
f 33 37 38 34
69+
f 34 38 39 35
70+
f 35 39 40 36
71+
f 37 33 36 40
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
o data
2+
v 0.150636968354 0.0265924208855 0.381051199365
3+
v 0.150636968354 0.0265924208855 0.581051199365
4+
v -0.0493630316458 0.0265924208855 0.581051199365
5+
v -0.0493630316458 0.0265924208855 0.381051199365
6+
v 0.150636968354 0.226592420885 0.381051199365
7+
v 0.150636968354 0.226592420885 0.581051199365
8+
v -0.0493630316458 0.226592420885 0.581051199365
9+
v -0.0493630316458 0.226592420885 0.381051199365
10+
f 1 2 3 4
11+
f 5 8 7 6
12+
f 1 5 6 2
13+
f 2 6 7 3
14+
f 3 7 8 4
15+
f 5 1 4 8
16+
v 0.149298049773 0.0561104909494 0.372439643663
17+
v 0.149298049773 0.0561104909494 0.572439643663
18+
v -0.0507019502265 0.0561104909494 0.572439643663
19+
v -0.0507019502265 0.0561104909494 0.372439643663
20+
v 0.149298049773 0.256110490949 0.372439643663
21+
v 0.149298049773 0.256110490949 0.572439643663
22+
v -0.0507019502265 0.256110490949 0.572439643663
23+
v -0.0507019502265 0.256110490949 0.372439643663
24+
f 9 10 11 12
25+
f 13 16 15 14
26+
f 9 13 14 10
27+
f 10 14 15 11
28+
f 11 15 16 12
29+
f 13 9 12 16
30+
v 0.26999895876 0.133748568294 0.307997501023
31+
v 0.26999895876 0.133748568294 0.507997501023
32+
v 0.0699989587596 0.133748568294 0.507997501023
33+
v 0.0699989587596 0.133748568294 0.307997501023
34+
v 0.26999895876 0.333748568294 0.307997501023
35+
v 0.26999895876 0.333748568294 0.507997501023
36+
v 0.0699989587596 0.333748568294 0.507997501023
37+
v 0.0699989587596 0.333748568294 0.307997501023
38+
f 17 18 19 20
39+
f 21 24 23 22
40+
f 17 21 22 18
41+
f 18 22 23 19
42+
f 19 23 24 20
43+
f 21 17 20 24
44+
v 0.0535650446424 0.000609069941433 0.387567031255
45+
v 0.0535650446424 0.000609069941433 0.587567031255
46+
v -0.146434955358 0.000609069941433 0.587567031255
47+
v -0.146434955358 0.000609069941433 0.387567031255
48+
v 0.0535650446424 0.200609069941 0.387567031255
49+
v 0.0535650446424 0.200609069941 0.587567031255
50+
v -0.146434955358 0.200609069941 0.587567031255
51+
v -0.146434955358 0.200609069941 0.387567031255
52+
f 25 26 27 28
53+
f 29 32 31 30
54+
f 25 29 30 26
55+
f 26 30 31 27
56+
f 27 31 32 28
57+
f 29 25 28 32
58+
v 0.106655730672 0.0896883241456 0.362573281688
59+
v 0.106655730672 0.0896883241456 0.562573281688
60+
v -0.0933442693282 0.0896883241456 0.562573281688
61+
v -0.0933442693282 0.0896883241456 0.362573281688
62+
v 0.106655730672 0.289688324146 0.362573281688
63+
v 0.106655730672 0.289688324146 0.562573281688
64+
v -0.0933442693282 0.289688324146 0.562573281688
65+
v -0.0933442693282 0.289688324146 0.362573281688
66+
f 33 34 35 36
67+
f 37 40 39 38
68+
f 33 37 38 34
69+
f 34 38 39 35
70+
f 35 39 40 36
71+
f 37 33 36 40

0 commit comments

Comments
 (0)