Interactive Graph Plotter Using Python, PictoBlox and Tobi

by vikasgovindrao in Teachers > 10

23 Views, 0 Favorites, 0 Comments

Interactive Graph Plotter Using Python, PictoBlox and Tobi

In this project, we will create an Interactive Graph Plotter using Python in PictoBlox.

The project allows the user to choose the type of graph they want to create and then enter their own data. The program uses Matplotlib to convert the data into a visual graph.

A Tobi sprite is also included to guide the user and provide messages during the process.

The project can create four different types of graphs:

  1. 📊 Bar Graph
  2. 📈 Line Graph
  3. 🥧 Pie Chart
  4. 🔵 Scatter Plot

This is a great project for learning Python, user input, loops, conditional statements, lists, functions and data visualization.

Supplies

You don't need any physical electronic components for this project.

Software

  1. PictoBlox
  2. Python Coding extension/environment
  3. Matplotlib library
  4. Tobi sprite

Create Tobi

Open PictoBlox and create a new Python project.

Add the Tobi sprite to your project.

We use Tobi to communicate with the user.

The basic command is:

tobi = Sprite("Tobi")

We then create a function that allows Tobi to display messages:

def speak(message):
tobi.say(str(message), 3)

Now we can use:

speak("Welcome!")

to make Tobi display a message.

Import Matplotlib

Matplotlib is a Python library used for creating graphs and visualizations.

Add:

import matplotlib.pyplot as plt

The pyplot module provides functions for creating different types of charts.

For example:

plt.bar()

creates a bar graph,

plt.plot()

creates a line graph,

plt.pie()

creates a pie chart, and

plt.scatter()

creates a scatter plot.

Take the User's Choice

The program asks the user which graph they want to create.

choice = input("Enter your choice (1-4): ")

The program then checks the choice using conditional statements.

if choice == "1":
# Bar Graph

elif choice == "2":
# Line Graph

elif choice == "3":
# Pie Chart

elif choice == "4":
# Scatter Plot

This allows the same program to create four different types of graphs.

Enter the Data

For each graph, the program asks the user to enter data.

For example, for a bar graph, the user can enter:

Category: Boys
Value: 25

Category: Girls
Value: 30

Category: Teachers
Value: 5

The category names are stored in one list:

labels = []

and the numerical values are stored in another:

values = []

The program adds the data using:

labels.append(label)
values.append(value)

Generate the Graph

After collecting the data, Matplotlib creates the selected graph.

Bar Graph

plt.bar(labels, values)

Line Graph

plt.plot(x_values, y_values, marker="o")

Pie Chart

plt.pie(
values,
labels=labels,
autopct="%1.1f%%"
)

Scatter Plot

plt.scatter(
x_values,
y_values
)

The program also adds titles and axis labels to make the graphs easier to understand.

Test Your Project

Run the program in PictoBlox.

Try the following example:

Select:

1

for a Bar Graph.

Enter:

How many categories? 4

Category 1: Maths
Value: 85

Category 2: Science
Value: 92

Category 3: English
Value: 78

Category 4: Computer
Value: 95

The program will automatically generate a bar graph showing the four values.

You can repeat the experiment with different data and different graph types

Project Link

https://drive.google.com/drive/folders/1ggM5srMvcFWTcI5RMcfIbLg6Zws07Q7x?usp=sharing