Skip to content

[OSAB] Task 3: Add 0-axis lines to scatterplots #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions bashplotlib/scatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,43 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs):
print(box_text(title, 2 * (len(get_scale(xs, False, size)) + 1)))

print("-" * (2 * (len(get_scale(xs, False, size)) + 2)))

# Iterate through all squares in the graph. For each square,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth trying to understand how this double-loop works. It's not necessarily the best way to solve this problem, and there are many alternative approaches one could take. See if you can come up with some.

# search through all the co-ordinates that we need to plot, and see
# if any of them should be plotted on the current graph square
# being considered.
for y in get_scale(ys, True, size):
print("|", end=' ')
for x in get_scale(xs, False, size):
point = " "
found_coord = False
for (i, (xp, yp)) in enumerate(zip(xs, ys)):
if xp <= x and yp >= y and (xp, yp) not in plotted:
point = pch
found_coord = True
plotted.add((xp, yp))
if cs:
colour = cs[i]
printcolour(point + " ", True, colour)

# If we did find a co-ordinate that needs plotting, make sure we
# plot it and not a 0-axis.
if found_coord:
char_to_plot = pch
else:
# The `get_scale` function always returns a scale that
# includes a 0.0 point, if the co-ordinates it is given cross
# 0 (i.e. include both negative and positive numbers).
#
# This means that we know that these conditions will trigger
# at some point if our co-ordinates cross 0.
if x == 0.0 and y == 0.0:
char_to_plot = "o"
elif x == 0.0:
char_to_plot = "|"
elif y == 0.0:
char_to_plot = "-"
else:
char_to_plot = " "

printcolour(char_to_plot + " ", True, colour)
print(" |")
print("-" * (2 * (len(get_scale(xs, False, size)) + 2)))

Expand Down