Chart Display in Python - The Advantages of Learning Python Programming for Beginners: A Comprehensive Guide

Latest

Dive into the world of Python programming with our comprehensive resources

Music

logo

Monday, April 17, 2023

Chart Display in Python

 

In this article, I’m making a simple graphic example. I’m providing a chart display of the data in the mysql database table.

 


 

 

 

 

 

 

 

import mysql.connector

import numpy as np

import matplotlib.pyplot as plt

 

# Connecting to MySql database

 

con1 = mysql.connector.connect(host="localhost",

                               user="root",

                               password="2344",

                               database="book")

cur1 = con1.cursor()

 

# Fecthing data from MySql to my python programme

 

cur1.execute("Select Author, Book, Price From worldclassics")

row_count = 5

 

#Fetch fewer rows from Mysql table using cursor’s fetchmany

 

result = cur1.fetchmany(row_count)

 

Books = []

Price = []

 

 

for row in result:

    Books.append(row[0]+"\n"+row[1])

    Price.append(row[2])

    

print("Book of Authors = ", Books)

print("Price of Authors = ", Price)

 

# Visualizing data using Matplotlib

 

plt.bar(Books, Price)

plt.ylim(0, 50)

plt.xlabel("Name of Authors")

plt.ylabel("Price of Books")

plt.title("Author's Information")

plt.show()

 

Hope to see you in the next article. Happy coding


No comments:

Post a Comment

Featured post

Python Introduction

What is Python? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built ...