Skip to content

Commit 5933873

Browse files
committed
Refactored to support Python3 and PEP-8 adjustments
1 parent 9df8227 commit 5933873

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

bashplotlib/histogram.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"""
77

88
from __future__ import print_function
9+
from __future__ import division
10+
911
import os
1012
import sys
1113
import math
@@ -147,7 +149,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def
147149

148150
if title:
149151
print(box_text(title, max(len(hist) * 2, len(title)), nlen))
150-
print
152+
print()
151153

152154
used_labs = set()
153155
for y in ys:
@@ -165,7 +167,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def
165167
printcolour(pch, True, colour)
166168
else:
167169
printcolour(" ", True, colour)
168-
print()
170+
print('')
169171
xs = hist.keys()
170172

171173
print(" " * (nlen + 1) + "-" * len(xs))
@@ -182,7 +184,7 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def
182184
print(num[i], end=' ')
183185
else:
184186
print(" ", end=' ')
185-
print
187+
print('')
186188

187189
center = max(map(len, map(str, [n, min_val, mean, max_val])))
188190
center += 15

bashplotlib/scatterplot.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@
55
Plotting terminal based scatterplots
66
"""
77

8+
from __future__ import print_function
89
import csv
910
import sys
1011
import optparse
1112
from .utils.helpers import *
12-
from .utils.commandhelp import scatter
13+
from .utils.commandhelp import scatter
1314

1415

1516
def get_scale(series, is_y=False, steps=20):
1617
min_val = min(series)
1718
max_val = max(series)
1819
scaled_series = []
19-
for x in drange(min_val, max_val, (max_val-min_val)/steps):
20+
for x in drange(min_val, max_val, (max_val - min_val) / steps):
2021
if x > 0 and scaled_series and max(scaled_series) < 0:
2122
scaled_series.append(0.0)
2223
scaled_series.append(x)
23-
24+
2425
if is_y:
2526
scaled_series.reverse()
2627
return scaled_series
@@ -29,21 +30,21 @@ def get_scale(series, is_y=False, steps=20):
2930
def plot_scatter(f, xs, ys, size, pch, colour, title):
3031
"""
3132
Form a complex number.
32-
33+
3334
Arguments:
3435
f -- comma delimited file w/ x,y coordinates
3536
xs -- if f not specified this is a file w/ x coordinates
3637
ys -- if f not specified this is a filew / y coordinates
3738
size -- size of the plot
3839
pch -- shape of the points (any character)
3940
colour -- colour of the points
40-
title -- title of the plot
41+
title -- title of the plot
4142
"""
42-
43+
4344
if f:
4445
if isinstance(f, str):
4546
f = open(f)
46-
47+
4748
data = [tuple(map(float, line.strip().split(','))) for line in f]
4849
xs = [i[0] for i in data]
4950
ys = [i[1] for i in data]
@@ -52,29 +53,29 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
5253
ys = [float(str(row).strip()) for row in open(ys)]
5354

5455
plotted = set()
55-
56+
5657
if title:
57-
print box_text(title, 2*len(get_scale(xs, False, size))+1)
58-
59-
print "-" * (2*len(get_scale(xs, False, size))+2)
58+
print(box_text(title, 2 * len(get_scale(xs, False, size)) + 1))
59+
60+
print("-" * (2 * len(get_scale(xs, False, size)) + 2))
6061
for y in get_scale(ys, True, size):
61-
print "|",
62+
print("|", end=' ')
6263
for x in get_scale(xs, False, size):
6364
point = " "
6465
for (i, (xp, yp)) in enumerate(zip(xs, ys)):
6566
if xp <= x and yp >= y and (xp, yp) not in plotted:
6667
point = pch
67-
#point = str(i)
68+
#point = str(i)
6869
plotted.add((xp, yp))
69-
if x==0 and y==0:
70+
if x == 0 and y == 0:
7071
point = "o"
71-
elif x==0:
72+
elif x == 0:
7273
point = "|"
73-
elif y==0:
74+
elif y == 0:
7475
point = "-"
7576
printcolour(point, True, colour)
76-
print "|"
77-
print "-"*(2*len(get_scale(xs, False, size))+2)
77+
print("|")
78+
print("-" * (2 * len(get_scale(xs, False, size)) + 2))
7879

7980

8081
def main():
@@ -85,9 +86,10 @@ def main():
8586
parser.add_option('-t', '--title', help='title for the chart', default="", dest='t')
8687
parser.add_option('-x', help='x coordinates', default=None, dest='x')
8788
parser.add_option('-y', help='y coordinates', default=None, dest='y')
88-
parser.add_option('-s', '--size',help='y coordinates', default=20, dest='size', type='int')
89-
parser.add_option('-p', '--pch',help='shape of point', default="x", dest='pch')
90-
parser.add_option('-c', '--colour', help='colour of the plot (%s)' % colour_help, default='default', dest='colour')
89+
parser.add_option('-s', '--size', help='y coordinates', default=20, dest='size', type='int')
90+
parser.add_option('-p', '--pch', help='shape of point', default="x", dest='pch')
91+
parser.add_option('-c', '--colour', help='colour of the plot (%s)' %
92+
colour_help, default='default', dest='colour')
9193

9294
opts, args = parser.parse_args()
9395

@@ -97,8 +99,8 @@ def main():
9799
if opts.f or (opts.x and opts.y):
98100
plot_scatter(opts.f, opts.x, opts.y, opts.size, opts.pch, opts.colour, opts.t)
99101
else:
100-
print "nothing to plot!"
102+
print("nothing to plot!")
101103

102104

103-
if __name__=="__main__":
105+
if __name__ == "__main__":
104106
main()

0 commit comments

Comments
 (0)