Skip to content
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

Turtles are very slow animals... #2

Open
adswa opened this issue Jan 15, 2019 · 4 comments
Open

Turtles are very slow animals... #2

adswa opened this issue Jan 15, 2019 · 4 comments

Comments

@adswa
Copy link

adswa commented Jan 15, 2019

I'm running into trouble with the creation of a scatterplot with kiva data in section 8.15. act_kiva_graph_2 (Create a well scaled scatter plot with X and Y axes using num_lenders_total and loan_amount).
The turtle is painstakingly slow, regardless of the speed parameter, and drawing the loan_amount-num_lenders_total scatterplot fails due to a RunTime Error after the turtle finished the second dot.

This error occurs consistently: it happens in the sandbox, it happens if I build runestone locally from the pbs-psych161-wi19 branch, it happens if I build runestone locally from the current state of runestone/ac101.

The same code runs flawless locally in an ipython instance using Python 3.5:

import turtle
sc = turtle.Screen()
adina = turtle.Turtle()
adina.speed(10)
sc.setworldcoordinates(0, 0, max(num_lenders_total), max(loan_amount))

adina.penup()

for i in range(len(num_lenders_total)):
    adina.goto(num_lenders_total[i], loan_amount[i])
    adina.stamp()

A workaround for me was to scale the loan_amount variable, as this one was clearly responsible for giving my poor turtle a hard time (very long ways to walk for it). The following code works AND is also able to adjust the speed:

loan_amount_scale = [i/500 for i in loan_amount]

import turtle
sc = turtle.Screen()
adina = turtle.Turtle()
adina.speed(0)
sc.setworldcoordinates(0, 0, max(num_lenders_total), max(loan_amount_scale))

adina.penup()

for i in range(len(num_lenders_total)):
    adina.goto(num_lenders_total[i], loan_amount_scale[i])
    adina.stamp()

But I doubt that this is an optimal solution...

@yarikoptic
Copy link
Member

Smells like this turtle is buggy! Thanks, I will check

@yarikoptic
Copy link
Member

didn't figure anything out so far besides adding a neat exercise to the "Sorting" chapter -- making this plotting faster altogether ;-)

@bnmnetp
Copy link

bnmnetp commented Jan 18, 2019

See also the docs for tracer method

@adswa
Copy link
Author

adswa commented Jan 18, 2019

Thanks, @bnmnetp, that indeed fixed the problem!

I used it in the following way, if anyone's interested:

# solution using tracer:
import turtle
sc = turtle.Screen()
sc.tracer(200, 25)
adina = turtle.Turtle()
adina.speed(0)
sc.setworldcoordinates(0, 0, max(num_lenders_total), max(loan_amount))

adina.penup()

for i in range(len(num_lenders_total)):
    adina.goto(num_lenders_total[i], loan_amount[i])
    adina.stamp()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants