Created a scatterplot

I would struggle toe write the scatterplot on my own.

If I were on my own in the scatterplot lab, I would struggled very much with this checkpoint.

As has happened in many cases so far, I believe I can do things conceptually, but struggle when it comes to actually coding them -- a language barrier so to speak.
This commit is contained in:
Mike 2023-08-18 11:07:40 -04:00
parent 0551181474
commit ce40afe923
3 changed files with 107 additions and 59 deletions

85
poetry.lock generated
View File

@ -159,13 +159,13 @@ files = [
[[package]] [[package]]
name = "furo" name = "furo"
version = "2023.7.26" version = "2023.8.17"
description = "A clean customisable Sphinx documentation theme." description = "A clean customisable Sphinx documentation theme."
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.7"
files = [ files = [
{file = "furo-2023.7.26-py3-none-any.whl", hash = "sha256:1c7936929ec57c5ddecc7c85f07fa8b2ce536b5c89137764cca508be90e11efd"}, {file = "furo-2023.8.17-py3-none-any.whl", hash = "sha256:baed406fc8f75a585caa330756b6841e6a1d4c844a3a355387e01ba9d1a4c6ee"},
{file = "furo-2023.7.26.tar.gz", hash = "sha256:257f63bab97aa85213a1fa24303837a3c3f30be92901ec732fea74290800f59e"}, {file = "furo-2023.8.17.tar.gz", hash = "sha256:56664be7290d1457a49d6c2c98cbf96537b9ee1cf05d28e05a5178e76abe5c55"},
] ]
[package.dependencies] [package.dependencies]
@ -285,13 +285,13 @@ files = [
[[package]] [[package]]
name = "pygments" name = "pygments"
version = "2.15.1" version = "2.16.1"
description = "Pygments is a syntax highlighting package written in Python." description = "Pygments is a syntax highlighting package written in Python."
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.7"
files = [ files = [
{file = "Pygments-2.15.1-py3-none-any.whl", hash = "sha256:db2db3deb4b4179f399a09054b023b6a586b76499d36965813c71aa8ed7b5fd1"}, {file = "Pygments-2.16.1-py3-none-any.whl", hash = "sha256:13fc09fa63bc8d8671a6d247e1eb303c4b343eaee81d861f3404db2935653692"},
{file = "Pygments-2.15.1.tar.gz", hash = "sha256:8ace4d3c1dd481894b2005f560ead0f9f19ee64fe983366be1a21e171d12775c"}, {file = "Pygments-2.16.1.tar.gz", hash = "sha256:1daff0494820c69bc8941e407aa20f577374ee88364ee10a98fdbe0aece96e29"},
] ]
[package.extras] [package.extras]
@ -342,13 +342,13 @@ files = [
[[package]] [[package]]
name = "sphinx" name = "sphinx"
version = "7.1.1" version = "7.2.2"
description = "Python documentation generator" description = "Python documentation generator"
optional = false optional = false
python-versions = ">=3.8" python-versions = ">=3.9"
files = [ files = [
{file = "sphinx-7.1.1-py3-none-any.whl", hash = "sha256:4e6c5ea477afa0fb90815210fd1312012e1d7542589ab251ac9b53b7c0751bce"}, {file = "sphinx-7.2.2-py3-none-any.whl", hash = "sha256:ed33bc597dd8f05cd37118f64cbac0b8bf773389a628ddfe95ab9e915c9308dc"},
{file = "sphinx-7.1.1.tar.gz", hash = "sha256:59b8e391f0768a96cd233e8300fe7f0a8dc2f64f83dc2a54336a9a84f428ff4e"}, {file = "sphinx-7.2.2.tar.gz", hash = "sha256:1c0abe6d4de7a6b2c2b109a2e18387bf27b240742e1b34ea42ac3ed2ac99978c"},
] ]
[package.dependencies] [package.dependencies]
@ -359,7 +359,7 @@ docutils = ">=0.18.1,<0.21"
imagesize = ">=1.3" imagesize = ">=1.3"
Jinja2 = ">=3.0" Jinja2 = ">=3.0"
packaging = ">=21.0" packaging = ">=21.0"
Pygments = ">=2.13" Pygments = ">=2.14"
requests = ">=2.25.0" requests = ">=2.25.0"
snowballstemmer = ">=2.0" snowballstemmer = ">=2.0"
sphinxcontrib-applehelp = "*" sphinxcontrib-applehelp = "*"
@ -372,7 +372,7 @@ sphinxcontrib-serializinghtml = ">=1.1.5"
[package.extras] [package.extras]
docs = ["sphinxcontrib-websupport"] docs = ["sphinxcontrib-websupport"]
lint = ["docutils-stubs", "flake8 (>=3.5.0)", "flake8-simplify", "isort", "mypy (>=0.990)", "ruff", "sphinx-lint", "types-requests"] lint = ["docutils-stubs", "flake8 (>=3.5.0)", "flake8-simplify", "isort", "mypy (>=0.990)", "ruff", "sphinx-lint", "types-requests"]
test = ["cython", "filelock", "html5lib", "pytest (>=4.6)"] test = ["cython (>=3.0)", "filelock", "html5lib", "pytest (>=4.6)", "setuptools (>=67.0)"]
[[package]] [[package]]
name = "sphinx-basic-ng" name = "sphinx-basic-ng"
@ -393,45 +393,54 @@ docs = ["furo", "ipython", "myst-parser", "sphinx-copybutton", "sphinx-inline-ta
[[package]] [[package]]
name = "sphinxcontrib-applehelp" name = "sphinxcontrib-applehelp"
version = "1.0.4" version = "1.0.7"
description = "sphinxcontrib-applehelp is a Sphinx extension which outputs Apple help books" description = "sphinxcontrib-applehelp is a Sphinx extension which outputs Apple help books"
optional = false optional = false
python-versions = ">=3.8" python-versions = ">=3.9"
files = [ files = [
{file = "sphinxcontrib-applehelp-1.0.4.tar.gz", hash = "sha256:828f867945bbe39817c210a1abfd1bc4895c8b73fcaade56d45357a348a07d7e"}, {file = "sphinxcontrib_applehelp-1.0.7-py3-none-any.whl", hash = "sha256:094c4d56209d1734e7d252f6e0b3ccc090bd52ee56807a5d9315b19c122ab15d"},
{file = "sphinxcontrib_applehelp-1.0.4-py3-none-any.whl", hash = "sha256:29d341f67fb0f6f586b23ad80e072c8e6ad0b48417db2bde114a4c9746feb228"}, {file = "sphinxcontrib_applehelp-1.0.7.tar.gz", hash = "sha256:39fdc8d762d33b01a7d8f026a3b7d71563ea3b72787d5f00ad8465bd9d6dfbfa"},
] ]
[package.dependencies]
Sphinx = ">=5"
[package.extras] [package.extras]
lint = ["docutils-stubs", "flake8", "mypy"] lint = ["docutils-stubs", "flake8", "mypy"]
test = ["pytest"] test = ["pytest"]
[[package]] [[package]]
name = "sphinxcontrib-devhelp" name = "sphinxcontrib-devhelp"
version = "1.0.2" version = "1.0.5"
description = "sphinxcontrib-devhelp is a sphinx extension which outputs Devhelp document." description = "sphinxcontrib-devhelp is a sphinx extension which outputs Devhelp documents"
optional = false optional = false
python-versions = ">=3.5" python-versions = ">=3.9"
files = [ files = [
{file = "sphinxcontrib-devhelp-1.0.2.tar.gz", hash = "sha256:ff7f1afa7b9642e7060379360a67e9c41e8f3121f2ce9164266f61b9f4b338e4"}, {file = "sphinxcontrib_devhelp-1.0.5-py3-none-any.whl", hash = "sha256:fe8009aed765188f08fcaadbb3ea0d90ce8ae2d76710b7e29ea7d047177dae2f"},
{file = "sphinxcontrib_devhelp-1.0.2-py2.py3-none-any.whl", hash = "sha256:8165223f9a335cc1af7ffe1ed31d2871f325254c0423bc0c4c7cd1c1e4734a2e"}, {file = "sphinxcontrib_devhelp-1.0.5.tar.gz", hash = "sha256:63b41e0d38207ca40ebbeabcf4d8e51f76c03e78cd61abe118cf4435c73d4212"},
] ]
[package.dependencies]
Sphinx = ">=5"
[package.extras] [package.extras]
lint = ["docutils-stubs", "flake8", "mypy"] lint = ["docutils-stubs", "flake8", "mypy"]
test = ["pytest"] test = ["pytest"]
[[package]] [[package]]
name = "sphinxcontrib-htmlhelp" name = "sphinxcontrib-htmlhelp"
version = "2.0.1" version = "2.0.4"
description = "sphinxcontrib-htmlhelp is a sphinx extension which renders HTML help files" description = "sphinxcontrib-htmlhelp is a sphinx extension which renders HTML help files"
optional = false optional = false
python-versions = ">=3.8" python-versions = ">=3.9"
files = [ files = [
{file = "sphinxcontrib-htmlhelp-2.0.1.tar.gz", hash = "sha256:0cbdd302815330058422b98a113195c9249825d681e18f11e8b1f78a2f11efff"}, {file = "sphinxcontrib_htmlhelp-2.0.4-py3-none-any.whl", hash = "sha256:8001661c077a73c29beaf4a79968d0726103c5605e27db92b9ebed8bab1359e9"},
{file = "sphinxcontrib_htmlhelp-2.0.1-py3-none-any.whl", hash = "sha256:c38cb46dccf316c79de6e5515e1770414b797162b23cd3d06e67020e1d2a6903"}, {file = "sphinxcontrib_htmlhelp-2.0.4.tar.gz", hash = "sha256:6c26a118a05b76000738429b724a0568dbde5b72391a688577da08f11891092a"},
] ]
[package.dependencies]
Sphinx = ">=5"
[package.extras] [package.extras]
lint = ["docutils-stubs", "flake8", "mypy"] lint = ["docutils-stubs", "flake8", "mypy"]
test = ["html5lib", "pytest"] test = ["html5lib", "pytest"]
@ -452,30 +461,36 @@ test = ["flake8", "mypy", "pytest"]
[[package]] [[package]]
name = "sphinxcontrib-qthelp" name = "sphinxcontrib-qthelp"
version = "1.0.3" version = "1.0.6"
description = "sphinxcontrib-qthelp is a sphinx extension which outputs QtHelp document." description = "sphinxcontrib-qthelp is a sphinx extension which outputs QtHelp documents"
optional = false optional = false
python-versions = ">=3.5" python-versions = ">=3.9"
files = [ files = [
{file = "sphinxcontrib-qthelp-1.0.3.tar.gz", hash = "sha256:4c33767ee058b70dba89a6fc5c1892c0d57a54be67ddd3e7875a18d14cba5a72"}, {file = "sphinxcontrib_qthelp-1.0.6-py3-none-any.whl", hash = "sha256:bf76886ee7470b934e363da7a954ea2825650013d367728588732c7350f49ea4"},
{file = "sphinxcontrib_qthelp-1.0.3-py2.py3-none-any.whl", hash = "sha256:bd9fc24bcb748a8d51fd4ecaade681350aa63009a347a8c14e637895444dfab6"}, {file = "sphinxcontrib_qthelp-1.0.6.tar.gz", hash = "sha256:62b9d1a186ab7f5ee3356d906f648cacb7a6bdb94d201ee7adf26db55092982d"},
] ]
[package.dependencies]
Sphinx = ">=5"
[package.extras] [package.extras]
lint = ["docutils-stubs", "flake8", "mypy"] lint = ["docutils-stubs", "flake8", "mypy"]
test = ["pytest"] test = ["pytest"]
[[package]] [[package]]
name = "sphinxcontrib-serializinghtml" name = "sphinxcontrib-serializinghtml"
version = "1.1.5" version = "1.1.8"
description = "sphinxcontrib-serializinghtml is a sphinx extension which outputs \"serialized\" HTML files (json and pickle)." description = "sphinxcontrib-serializinghtml is a sphinx extension which outputs \"serialized\" HTML files (json and pickle)"
optional = false optional = false
python-versions = ">=3.5" python-versions = ">=3.9"
files = [ files = [
{file = "sphinxcontrib-serializinghtml-1.1.5.tar.gz", hash = "sha256:aa5f6de5dfdf809ef505c4895e51ef5c9eac17d0f287933eb49ec495280b6952"}, {file = "sphinxcontrib_serializinghtml-1.1.8-py3-none-any.whl", hash = "sha256:27849e7227277333d3d32f17c138ee148a51fa01f888a41cd6d4e73bcabe2d06"},
{file = "sphinxcontrib_serializinghtml-1.1.5-py2.py3-none-any.whl", hash = "sha256:352a9a00ae864471d3a7ead8d7d79f5fc0b57e8b3f95e9867eb9eb28999b92fd"}, {file = "sphinxcontrib_serializinghtml-1.1.8.tar.gz", hash = "sha256:aaf3026335146e688fd209b72320314b1b278320cf232e3cda198f873838511a"},
] ]
[package.dependencies]
Sphinx = ">=5"
[package.extras] [package.extras]
lint = ["docutils-stubs", "flake8", "mypy"] lint = ["docutils-stubs", "flake8", "mypy"]
test = ["pytest"] test = ["pytest"]

View File

@ -34,10 +34,31 @@ def draw_scatterplot(data, size=5, color="black"):
draw_points(data, color, size) draw_points(data, color, size)
def draw_axes(data): 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): def draw_points(data, color, size):
"Draws the scatter plot's points." 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(): with no_delay():
data = generate_data(50, 10, 500, 5, 400, 1000) data = generate_data(50, 10, 500, 5, 400, 1000)

View File

@ -5,39 +5,51 @@
# None of them are finished; this is your job! # None of them are finished; this is your job!
def maximum(data): def maximum(data):
"Returns the largest number in data" highest = None
raise NotImplementedError for number in data:
if highest is None:
highest = number
if number > highest:
highest = number
return highest
def minimum(data): def minimum(data):
"Returns the smallest number in data" lowest = None
raise NotImplementedError for number in data:
if lowest is None:
lowest = number
if number < lowest:
lowest = number
return lowest
def bounds(data): def bounds(data):
"Returns a list of the smallest and largest numbers in data" return [minimum(data), maximum(data)]
raise NotImplementedError
def clamp(value, low, high): def clamp(value, low, high):
"""Clamps a value to a range from low to high. if value < low:
Returns value if it is between low and high. return low
If value is lower than low, returns low. If value is higher than high, returns high. if value > high:
""" return high
raise NotImplementedError return value
def ratio(value, start, end): def ratio(value, start, end):
"""Returns a number from 0.0 to 1.0, representing how far along value is from start to end. r=(value - start)/(end - start)
The return value is clamped to [0, 1], so even if value is lower than start, the return return clamp(r, 0, 1)
value will not be lower than 0.0.
"""
raise NotImplementedError
def scale(value, domain_min, domain_max, range_min, range_max): def scale(value, domain_min, domain_max, range_min, range_max):
"Given a value within a domain, returns the scaled equivalent within range." r=ratio(value, domain_min, domain_max)
raise NotImplementedError return range_min + r * (range_max - range_min)
def get_x_values(points): def get_x_values(points):
"Returns the first value for each point in points." x_values=[]
raise NotImplementedError for x, y in points:
x_values.append(x)
return x_values
def get_y_values(points): def get_y_values(points):
"Returns the second value for each point in points." y_values=[]
raise NotImplementedError for x, y in points:
y_values.append(y)
return y_values