Python Interest grid with Ticks

from graphics import *

   



rate = float(input('what is the loan interst rate? [%]: '))/100/12

balance = float(input('Starting balance: '))


maxValue = 10000

interval = 1000

def createLabeledWindow(maxValue, interval):

    

    

    W, H = 400, 400

    maxYear =7

    padYears, padValue = 0.75, 0.1*maxValue


    win = GraphWin('Bar plot of Account Balance', W, H)

    win.setCoords(-padYears, -padValue, maxYear, maxValue)

    win.setBackground('gold')


    xax = Line(Point(0, 0), Point(maxYear, 0))

    yax = Line(Point(0, 0), Point(0, maxValue))

    xax.setOutline('indianred'), yax.setOutline('indianred')

    xax.setWidth(2), yax.setWidth(3)

    yax.draw(win), xax.draw(win)

    

    # draw on y tick marks and labels

    for i in range(0 , maxValue+1, interval):

        #print(i)

        tick = Line(Point(-0.1, i), Point(0, i))

        tick.setOutline('indianred')

        tick.draw(win)

        #tick.draw(win)

        label = Text(Point(-0.3, i), i)

        label.setSize(8)

        label.draw(win)

        

        # draw a line at current y position

    for t in range(0 ,maxYear+1):

        stroke = Line(Point(t, 0), Point(t, -0.02*maxValue))

        stroke.setOutline('indianred')

        stroke.draw(win)


        xlabel = Text(Point(t , -0.04*maxValue), t)

        xlabel.setSize(8)

        xlabel.draw(win)

        # add a label $1000, $2000... at current y position

    

    # draw on x tick marks and labels



    # label below the tick


    return win

#payment = float(input('monthly payment: '))



# month = 0


# for i in range(12):

#     interest = round(balance*rate,2)

#     principle = round(payment - interest,2)

#     newbalance = round(balance + interest - payment,2)

    

    

#     month = month + 1 

    

#     balance = newbalance

    

# labels = ("Total Interest", "Total Principal", "Final Balance", "Start Balance")



# month = Rectangle(Point(padYears, f'{month}'),Point(20, maxValue))

# month.setFill('palegreen')

# month.draw(win)


# balance = Rectangle(Point(padYears, f'{balance}'),Point(0 ,padValue))

# balance.setFill('orange')

# balance.draw(win)


# interest = Rectangle(Point(20, padValue),Point(maxValue, f'{interest}'))

# interest.setFill('pink')

# interest.draw(win)


# principle = Rectangle(Point( maxValue, f'{principle}'),Point(0 , padValue))

# principle.setFill('purple')

# principle.draw(win)


# newbalance = Rectangle(Point(maxValue, 20),Point(maxValue, f'{newbalance}'))

# newbalance.setFill('palegreen')

# newbalance.draw(win)


win = createLabeledWindow(maxValue, interval)


_=win.getMouse()

win.close()


    


0 Kudos

Comments

Displaying 0 of 0 comments ( View all | Add Comment )