mod'd scatterplot.py to draw axes and plot points

I was all worried about how I was going to scale the axes and make the tick marks
and then it was already part of the template! That said, it was super helpful to
be able to see under the hood on how all the formatting and setup was done.

Overall the process went well. Having the structure for part of drawing the axes
made that section very smooth. I had made a typo in the dtaw_points portion where
I had used () instead of [] when indexing a list amd the error message was just
cryptic enough to make me think I had made some other, more serious mistake after
correcting the typo; turns out, I had just not resaved scatterplot.py after correcting
so of course I was going to keep getting the same error message. Other than that,
the assignment was straightforward and implementing the functions we made in transform.py
was easy enough to get the axes drawn and points plotted. I'm happy with how it turned out.

Top-down design made this process accessible, as far as I'm concerned. Without breaking
this up into small steps, there's no way I would have been able to do this all at once.
I really appreciated your clarity and breakdown throughout the prompt. The whole system
up to this point has been a great model for how I need to approach projects/labs in the
future with my courses. When I was teaching physics, it was sort of second-nature to go
through an example, break down a problem, and then have the students apply it themselves
but one thing I haven't dialed in on the cs-side yet is how much do I give to the students
and at what point can they do it themselves. I usually fall into the trap of wanting them
to do too much too fast and when they're confronted with a problem they (think they) can't
solve, they shut down.
This commit is contained in:
Pat Wick 2023-08-04 14:10:12 -04:00
parent 618d9687c2
commit e4f8fb93e8
1 changed files with 24 additions and 0 deletions

View File

@ -35,9 +35,33 @@ def draw_scatterplot(data, size=5, color="black"):
def draw_axes(data):
"Draws the scatter plot's axes."
draw_x_axis()
x_values = get_x_values(data)
xmin, xmax = bounds(x_values)
ticks = get_tick_values(xmin, xmax)
for tick in ticks:
screen_x_position = scale(tick, xmin, xmax, 0, constants.PLOT_WIDTH)
draw_x_tick(screen_x_position, tick)
draw_y_axis()
y_values = get_y_values(data)
ymin, ymax = bounds(y_values)
ticks = get_tick_values(ymin, ymax)
for tick in ticks:
screen_y_position = scale(tick, ymin, ymax, 0, constants.PLOT_HEIGHT)
draw_y_tick(screen_y_position, tick)
def draw_points(data, color, size):
"Draws the scatter plot's points."
x_values = get_x_values(data)
y_values = get_y_values(data)
xmin, xmax = bounds(x_values)
ymin, ymax = bounds(y_values)
for i in range(len(x_values)):
scaled_x = scale(x_values[i], xmin, xmax, 0, constants.PLOT_WIDTH)
scaled_y = scale(y_values[i], ymin, ymax, 0, constants.PLOT_HEIGHT)
draw_point(scaled_x, scaled_y, color, size)
with no_delay():
data = generate_data(50, 10, 500, 5, 400, 1000)