# HSSlive: Plus One & Plus Two Notes & Solutions for Kerala State Board

## How to Draw a Graph Using Python Turtle, Tkinter, Matplotlib & Without Libraries

How to Draw a Graph in Python - There are various methods to create a Graph using python libraries like turtle, tkinter and matplotlib. Also, you will learn how to make a Graph using python in easy and simple steps. We have also provided the python code for drawing a Graph pattern. If you have introductory to intermediate knowledge in Python and statistics, then you can use this article as a one-stop shop for building and plotting Graph patterns in Python using libraries from its scientific stack, including NumPy, Matplotlib, Pandas, and Seaborn.

Plotting a Graph in python is a simple procedure, and python in its simplest provides multiple easy methods to do so.

## How to Draw a Graph using Python?

Given below is the process to draw a Graph in python using libraries like Turtle, Tkinter, Matplotib and others.

Four Method to make a Graph in Python using multiple libraries:

1. How to draw a Graph using python turtle?
2. How to draw a Graph using python tkinter?
3. How to draw a Graph using python matplotlib?
4. How to draw a Graph using python code without library?

## How to Draw a Graph using Python Turtle?

Check below step by step process to make a Graph using the python turtle library.

Step

• Import turtle
• Set screen
• Make turtle
• Draw the y-axis lines
• Draw the x-axis lines
• Draw the x-axis and y-axis with labeling.

Code

# import package and making objects
import turtle

sc=turtle.Screen()
trtl=turtle.Turtle()

# method to draw y-axis lines
def drawy(val):

# line
trtl.forward(300)

# set position
trtl.up()
trtl.setpos(val,300)
trtl.down()

# another line
trtl.backward(300)

# set position again
trtl.up()
trtl.setpos(val+10,0)
trtl.down()

# method to draw y-axis lines
def drawx(val):

# line
trtl.forward(300)

# set position
trtl.up()
trtl.setpos(300,val)
trtl.down()

# another line
trtl.backward(300)

# set position again
trtl.up()
trtl.setpos(0,val+10)
trtl.down()

# method to label the graph grid
def lab():

# set position
trtl.penup()
trtl.setpos(155,155)
trtl.pendown()

# write 0
trtl.write(0,font=("Verdana", 12, "bold"))

# set position again
trtl.penup()
trtl.setpos(290,155)
trtl.pendown()

# write x
trtl.write("x",font=("Verdana", 12, "bold"))

# set position again
trtl.penup()
trtl.setpos(155,290)
trtl.pendown()

# write y
trtl.write("y",font=("Verdana", 12, "bold"))

# Main Section
# set screen
sc.setup(800,800)

# set turtle features
trtl.speed(100)
trtl.left(90)
trtl.color('lightgreen')

# y lines
for i in range(30):
drawy(10*(i+1))

# set position for x lines
trtl.right(90)
trtl.up()
trtl.setpos(0,0)
trtl.down()

# x lines
for i in range(30):
drawx(10*(i+1))

# axis
trtl.color('green')

# set position for x axis
trtl.up()
trtl.setpos(0,150)
trtl.down()

# x-axis
trtl.forward(300)

# set position for y axis
trtl.left(90)
trtl.up()
trtl.setpos(150,0)
trtl.down()

# y-axis
trtl.forward(300)

# labeling
lab()

# hide the trtle
trtl.hideturtle()

Output

 How to Draw a Graph Using Python Turtle, Tkinter, Matplotlib & Without Libraries

## How to Draw a Graph using Python Tkinter?

Check below step by step process to make a Graph using the python tkinter library.

Step

Code

Output

## How to Draw a Graph using Python Matplotlib?

Check below step by step process to make a Graph using the python matplotlib library.

Step

Code

Output

## How to Draw a Graph using Python Code without Library?

Step

Code

Output

Note: Also, these codes might not run in an online compiler please use an offline compiler. Programmers can make any changes in the code according to their specific requirement.

## Conclusion on How to Draw a Graph using Python

We hope the programs and methods provided above on how to make a Graph using python libraries have been helpful to you. If there is any issue in any of the code please let us know in the comments. We will try to resolve it as soon as possible.

Share: