Skip to content

Commit 1402061

Browse files
committed
[PPAB] Add axis lines to the middle of scatterplots
1 parent a7a0574 commit 1402061

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

bashplotlib/scatterplot.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,41 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs):
3434
if title:
3535
print(box_text(title, 2 * (len(get_scale(xs, False, size)) + 1)))
3636

37+
# Iterate through all points on the x- and y-scale. For each point,
38+
# search through all the co-ordinates that we need to plot, and see
39+
# if any of them should be plotted on the current point being considered.
3740
print("-" * (2 * (len(get_scale(xs, False, size)) + 2)))
3841
for y in get_scale(ys, True, size):
3942
print("|", end=' ')
4043
for x in get_scale(xs, False, size):
41-
point = " "
44+
found_point = False
4245
for (i, (xp, yp)) in enumerate(zip(xs, ys)):
4346
if xp <= x and yp >= y and (xp, yp) not in plotted:
44-
point = pch
47+
found_point = True
4548
plotted.add((xp, yp))
4649
if cs:
4750
colour = cs[i]
48-
printcolour(point + " ", True, colour)
51+
52+
char_to_plot = None
53+
if found_point:
54+
char_to_plot = pch
55+
else:
56+
# The `get_scale` function always returns a scale that
57+
# includes a 0.0 point, if the co-ordinates it is given cross
58+
# 0 (i.e. include both negative and positive numbers).
59+
#
60+
# This means that we know that these conditions will trigger
61+
# at some point if our co-ordinates cross 0.
62+
if x == 0.0 and y == 0.0:
63+
char_to_plot = "o"
64+
elif x == 0.0:
65+
char_to_plot = "|"
66+
elif y == 0.0:
67+
char_to_plot = "-"
68+
else:
69+
char_to_plot = " "
70+
71+
printcolour(char_to_plot + " ", True, colour)
4972
print(" |")
5073
print("-" * (2 * (len(get_scale(xs, False, size)) + 2)))
5174

0 commit comments

Comments
 (0)