Draw a Graph Paper in Python Using Turtle

(Last Updated On: 13/10/2023)

Python Program to Draw a Graph Paper Using Turtle

# Python Program to Create a graph paper using turtle

# import turtle
import turtle
t=turtle.Turtle()
t.speed(10)

# graph lines
for i in range(0,400,20):
  t.pencolor('lightgrey')
  t.penup()
  t.setpos(-200+i,-200)
  if i==0:
    t.left(90)
    t.pendown()
    t.forward(400)
    t.backward(400)
for i in range(0,400,20):
      t.pencolor('lightgrey')
      t.penup()
      t.setpos(-200,-200+i)
      if i==0:
         t.right(90)
      t.pendown()
      t.forward(400)
      t.backward(400)
t.penup()
t.home()
t.pendown()

# axis
t.pencolor('black')
t.backward(200)
t.forward(400)
t.backward(200)
t.left(90)
t.forward(200)
t.backward(400)
t.penup()
t.setpos(5,5)
t.pendown()
t.write(0)
t.penup()
t.setpos(190,5)
t.pendown()
t.write("x")
t.penup()
t.setpos(5,190)
t.pendown()
t.write("y")
t.penup()
t.setpos(80,-180)
t.pendown()

t.ht()

Output:

Draw a Graph Paper in Python Using Turtle

About The Author

Leave a Reply