Kathryn Odell-Hamilton

2023.9.12

This is updated information and code within planning_scatter.md,
transform.py and scatterplot.py.

Thank you very much for the video explaining how to transform.py and
scatterplot.py.

Checkpoint 1
Writing scatterplot on my own after watching the video is better the
second time, but I'd have to go back slowly step by step. I would
make a copy of the scatterplot files to experiment for a better
understanding. Planning the scatterplot was fine. I used more detailed
information that in your video.

Checkpoint 2
In transform.py, I understood most of transforming data with functions,
but after your step-by-step video it was very clear. When I previously
go stuck, I did not know how to solve the code. Some things such as
using "clamp" for "return clamp(unclamped_ratio, 0, 1)" that's were it
is abstract. How do I figure out what to write for the inside code such
as "clamp" for the function? Do I reuse words from the "function name"?

I wrote a lot of comments so I can go back to review.

Checkpoint 3
In scatterplot.py, I understood the beginning with draw_axes for both
x and y points. What was confusing to code "Drawing the points" even
with you writing out the plan. You're video explaining this was
excellent, crystal clear.

I know now how to condense the code within the function such as
"xmin, xmax = bounds(get_x_values(data))". I wrote the code out the
long way.

For the scaled_y, I wasn't thinking about using the PLOT_HEIGHT until
your video. The first time looking at scatterplot.py, I shut down at the
end section, but now I understand it.

Running the scatterplot was so great to see visually. Definitely
more involved than creating a scatterplot in Seaborn.

Question: After I run the scatterplot to see visually, how do I get
back to lab_scatter? I tried cd ~, but it didnt' work. So, I quit out of
terminal and started over.

Thank you again for the video explaining everything.

______
Originally Completed 2023.8.25
Questions Submitted

Within Unit 2, lab_scatter, I used the top-down method for
planning_scatter.md, transform.py writing code to transform data with
function, and build the scatter plot. I'm requesting assistance to
complete several sections within transform.py and scatterplot.py files.

Checkpoint 1
I believe I could write about a quarter or small segments of the code
for the scatterplot.py, but would not be able to complete it without
guidance from an instructor. The top-down method to break down the
process of the scatterplot into small blocks was straight forward when
thinking, planning, and writing it out.

Honestly, I wouldn't know how to begin the scatterplot program without
additional information and instruction from the instructor. It's
abstract and frustrating. I don't have the background experience
using Python.

Checkpoint 2

From 2.1, minimum to 2.4, clamp, I understood how to and code the
simple functions with transforming data. From 2.5, ratio to the end,
2.8, get_y_values, I was confused and lost. I felt the information
provided was minimal, my perspective only. I could look back to the
beginning information to use some of the strategies, but unable to
complete these sections. I rewatched the videos and searched within
Discord to see what issues if any my colleagues were faced with.
There was little information online about transforming data with
functions using def statements with only a return and not printing.
More examples and explanation needed to be provided to better
understand what was expected.

Checkpoint 3

The program scatterplot.py is incomplete with the following:
     Find the scaled y-position for the point.
     Use draw_point(scaled_x, scaled_y, color, size) to draw the point.

Also, it won't run correctly because transform.py file is incomplete.
     Sections 2.5, ratio to the end, 2.8, get_y_values

I understood the scatterplot.py and how the data from the other
files was imported into this program file. From Checkpoint 1,
I would have still used the same format and structure. You could
create programs to visualize data such at charts and diagrams.
This commit is contained in:
kathrynoh23 2023-09-12 10:57:51 -04:00
parent b8d6ce9be7
commit 544d029267
7 changed files with 285 additions and 29 deletions

View File

@ -2,3 +2,5 @@ PLOT_HEIGHT = 400
PLOT_WIDTH = 400
PLOT_PADDING = 20
TICK_LENGTH = 5
"""Write in all caps."""

View File

@ -0,0 +1,51 @@
# Planning the scatter plot
# 9.12.2023_Watched the video "August 2_Scatter plot lab live-coding"
# ??? Was my pseudocode ok, going into it in more detail?
# My pseudocode here, below is your pseudocode from video
- from turtle import *
- Draw a scatter plot.
- Draw the axes.
- Draw the x-axis.
- Draw the horizontal line.
- Draw 6 ticks (short dashed lines) touching beneath the baseline of x-axis at minimum to maximum
location points "14 100 200 300 400 492" evenly spaced across at every 100.
- Name x axis labels "14 100 200 300 400 492" centered underneath the x axis ticks.
- Draw the y-axis.
- Draw the vertical line.
- Draw 6 ticks (short dashed lines) touching to the left side of the y-axis line at minimum to
maximum location points "-927 0 1000 2000 3000 3710" evenly spaced across at every 1,000.
- Name the y-axis labels to the left of the y axis ticks.
- Plot the data points.
Creating a visualization of graph with dots representing data points at x-y locations.
- ?Determine the screen size.
- Set the x-axis value ranges from 14 to 492.
_ Set the y-axis value ranges from -927 to 3710.
- Define the "data_points" function.
- Set the dot style.
- Set the dot size.
- Set the dot color.
- Define a scatter function to plot the "x, y" data points.
- ? Set a function to show the plot.
# Your pseudocode from video
- from turtle import *
- Draw a scappter plot.
- Draw the axes.
- Draw the x-axis.
- Draw the line.
- Figure out where the ticks should go
- For each tick,
- Draw the tick.
- Draw the y-axis.
- Draw the line.
- Figure out where the ticks should go
- For each tick,
- Draw the tick.
- Plot the points.
- For each point,
- Draw the point at the appropriate location.

6
poetry.lock generated
View File

@ -159,13 +159,13 @@ files = [
[[package]]
name = "furo"
version = "2023.8.19"
version = "2023.9.10"
description = "A clean customisable Sphinx documentation theme."
optional = false
python-versions = ">=3.8"
files = [
{file = "furo-2023.8.19-py3-none-any.whl", hash = "sha256:12f99f87a1873b6746228cfde18f77244e6c1ffb85d7fed95e638aae70d80590"},
{file = "furo-2023.8.19.tar.gz", hash = "sha256:e671ee638ab3f1b472f4033b0167f502ab407830e0db0f843b1c1028119c9cd1"},
{file = "furo-2023.9.10-py3-none-any.whl", hash = "sha256:513092538537dc5c596691da06e3c370714ec99bc438680edc1debffb73e5bfc"},
{file = "furo-2023.9.10.tar.gz", hash = "sha256:5707530a476d2a63b8cad83b4f961f3739a69f4b058bcf38a03a39fa537195b2"},
]
[package.dependencies]

View File

@ -33,6 +33,9 @@ def draw_scatterplot(data, size=5, color="black"):
draw_axes(data)
draw_points(data, color, size)
"""I understood from instructions and 1st try how to draw_axes for both x and y values.
Oh, to use the PLOT.HEIGHT for y because it's the vertical."""
def draw_axes(data):
"Draws the scatter plot's axes."
draw_x_axis()
@ -49,12 +52,33 @@ def draw_axes(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_WIDTH)
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."
"""THE PLAN
Find the x-bounds and the y-bounds of the data. You'll need these for scaling.
Can shorten by using:
xmin, xmax = bounds(get_x_values(data))
ymin, ymax = bounds(get_y_values(data))
For each point in the data
for points in data: or for x, y in data:
Get the x and y value from the point.
Find the scaled x-position for the point.
Find the scaled y-position for the point.
Use draw_point(scaled_x, scaled_y, color, size) to draw the point."""
x_values = get_x_values(data)
xmin, xmax = bounds(x_values)
y_values = get_y_values(data)
ymin, ymax = bounds(y_values)
for x, y in data:
scaled_x = scale(x, xmin, xmax, 0, constants.PLOT_WIDTH)
scaled_y = scale(y, 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)
draw_scatterplot(data, size=5, color="blue")

View File

@ -0,0 +1,62 @@
# scatterplot.py
# ------------
# By MWC Contributors
# Uses lots of helper functions in other modules to draw a scatter plot.
from turtle import *
from superturtle.movement import no_delay
import constants
from generate_data import generate_data
from ticks import get_tick_values
from plotting import (
prepare_screen,
draw_x_axis,
draw_y_axis,
draw_x_tick,
draw_y_tick,
draw_point,
)
from transform import (
maximum,
minimum,
bounds,
clamp,
ratio,
scale,
get_x_values,
get_y_values,
)
def draw_scatterplot(data, size=5, color="black"):
"Draws a scatter plot, showing the data"
prepare_screen()
draw_axes(data)
draw_points(data, color, size)
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()
"Draws the scatter plot's axes."
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_WIDTH)
draw_y_tick(screen_y_position, tick)
def draw_points(data, color, size):
"Draws the scatter plot's points."
with no_delay():
data = generate_data(50, 10, 500, 5, 400, 1000)
draw_scatterplot(data, size=5, color="blue")
hideturtle()
done()

View File

@ -4,6 +4,8 @@
# The functions in this module transform data.
# None of them are finished; this is your job!
# Corrected on 9.12.2023 from watching video, August 2_Scatter plot lab live-coding
def maximum(data):
"Returns the largest number in data"
largest = None
@ -14,6 +16,15 @@ def maximum(data):
largest = number
return largest
"""Find minimum Data is a list of numbers, such as [3, 5, 7, 6, 4, 2]
number = ?
smallest = ?
example: if number = 3
example: if 3 is the only number, than smallest = 3
then you go through the numbers in the list [3, 5, 7, 6, 4, 2]
so number = 2
lowest = 2, because it's smaller than 3, now 2 becomes the smallest number
For a considerable large amount of numbers you will use the code for the smallest number"""
def minimum(data):
"Returns the smallest number in data"
smallest = None
@ -24,22 +35,31 @@ def minimum(data):
smallest = number
return smallest
"""
The "scope of a variable" doesn't relate to the above defined functions, it's separate in it's on function.
smallest and largest changed from "None" to "minimum(data)" and "maximum(data)"
I didn't need to use "for and if else statments. Keep it simple.
I was on track with Last line need to add brackets [ ]
Also, you can define the function on 1 line.
return[minimum(data), maximum(data)]
"""
def bounds(data):
"Returns a list of the smallest and largest numbers in data"
smallest = None
largest = None
for numbers in data:
if numbers < smallest:
smallest = numbers
elif numbers > largest:
largest = numbers
return smallest, largest
smallest = minimum(data)
largest = maximum(data)
return [smallest, largest]
def clamp(value, low, high):
"""Clamps a value to a range from low to high.
Returns value if it is between low and high.
If value is lower than low, returns low. If value is higher than high, returns high.
"""
"""I did this correctly.
I learned the if, else if, else statement from Java classes. I like using "elif". """
if value < low:
return low
elif value > high:
@ -52,34 +72,46 @@ def ratio(value, start, end):
The return value is clamped to [0, 1], so even if value is lower than start, the return
value will not be lower than 0.0.
"""
"""ratio(-1, 0, 10)
-0.1"""
"""Ratio is function to find how much what percentage is finished from start to end.
Find out what's the relationship between how far you've gone from start
to the whole distance you have to go.
unclamped_ratio = (value - start) / (end - start) correct except for unclamped_ratio, I used value.
return amount_already_finished / total_distance_to_cover
I get confused with the wording such as using "clamp and unclamped_ratio." """
"""??? Is this correct?"""
value = (value - start) / (end - start)
if value >= 0:
return 0
elif value <= 1.0:
return 1.0
else:
return value
unclamped_ratio = (value - start) / (end - start)
return clamp(unclamped_ratio, 0, 1)
def scale(value, domain_min, domain_max, range_min, range_max):
"Given a value within a domain, returns the scaled equivalent within range."
"""???? I'm unsure how to code def scale"""
"""This is correct, but for using return range
value = range_min + r * (range_max - range_min)
I had to define what "r" is. I understand. """
return value
r = ratio(value, domain_min, domain_max)
return range_min + r * (range_max - range_min)
"""Points: [[1, 1], [2, 2], [4, 3], [7, 3]]
List of x and y points on a plane. You're probably going plot on a grid.
Can begin with
for x, y points in points: -It's unpacking, the x and y values
... get the x value, and add it to the x_values
the ".append" goes through each x value."""
def get_x_values(points):
"Returns the first value for each point in points."
"""???? I'm unsure how to code def get_x_values"""
points = x_values
return value
x_values = []
for x, y in points:
x_values.append(x)
return x_values
def get_y_values(points):
"Returns the second value for each point in points."
"""???? I'm unsure how to code def get_y_values"""
points = y_values
return value
y_values = []
for x, y in points:
y_values.append(y)
return y_values

View File

@ -0,0 +1,85 @@
# transform.py
# ------------
# By MWC Contributors
# The functions in this module transform data.
# None of them are finished; this is your job!
def maximum(data):
"Returns the largest number in data"
largest = None
for number in data:
if largest is None:
largest = number
if number > largest:
largest = number
return largest
def minimum(data):
"Returns the smallest number in data"
smallest = None
for number in data:
if smallest is None:
smallest = number
if number < smallest:
smallest = number
return smallest
def bounds(data):
"Returns a list of the smallest and largest numbers in data"
smallest = None
largest = None
for numbers in data:
if numbers < smallest:
smallest = numbers
elif numbers > largest:
largest = numbers
return smallest, largest
def clamp(value, low, high):
"""Clamps a value to a range from low to high.
Returns value if it is between low and high.
If value is lower than low, returns low. If value is higher than high, returns high.
"""
if value < low:
return low
elif value > high:
return high
else:
return value
def ratio(value, start, end):
"""Returns a number from 0.0 to 1.0, representing how far along value is from start to end.
The return value is clamped to [0, 1], so even if value is lower than start, the return
value will not be lower than 0.0.
"""
"""??? Is this correct?"""
value = (value - start) / (end - start)
if value >= 0:
return 0
elif value <= 1.0:
return 1.0
else:
return value
def scale(value, domain_min, domain_max, range_min, range_max):
"Given a value within a domain, returns the scaled equivalent within range."
"""???? I'm unsure how to code def scale"""
value = range_min + r * (range_max - range_min)
return value
def get_x_values(points):
"Returns the first value for each point in points."
"""???? I'm unsure how to code def get_x_values"""
points = x_values
return value
def get_y_values(points):
"Returns the second value for each point in points."
"""???? I'm unsure how to code def get_y_values"""
points = y_values
return value