0% found this document useful (0 votes)
4 views4 pages

55 matplotlib

The document provides a comprehensive guide on plotting data from a CSV file using Python's matplotlib library, covering reading data, creating plots, and saving images. It includes sample code for both a basic approach using the csv module and a cleaner version using pandas. Additionally, it features a project description, interview preparation tips, and information about the author, Gowtham SB, a data engineering expert and educator.

Uploaded by

joanantoranjith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

55 matplotlib

The document provides a comprehensive guide on plotting data from a CSV file using Python's matplotlib library, covering reading data, creating plots, and saving images. It includes sample code for both a basic approach using the csv module and a cleaner version using pandas. Additionally, it features a project description, interview preparation tips, and information about the author, Gowtham SB, a data engineering expert and educator.

Uploaded by

joanantoranjith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Gowtham SB

www.linkedin.com/in/sbgowtham/ Instagram - @dataengineeringtamil

🎯 FINAL GUIDE: Plotting from CSV using


matplotlib

✅ What You’ll Learn


● Read data from a CSV file

● Plot graphs using matplotlib

● Add labels, titles, grids

● Save your plot as an image

📄 Sample CSV File (data.csv)


Month,Sales
January,100
February,120
March,90
April,150

🧠 Python Code (Without Pandas)


import matplotlib.pyplot as plt
import csv

months = []
sales = []

# Reading the CSV file


with open('data.csv', 'r') as file:
reader = csv.DictReader(file)
for row in reader:
months.append(row['Month'])
sales.append(int(row['Sales']))
Gowtham SB
www.linkedin.com/in/sbgowtham/ Instagram - @dataengineeringtamil

# Creating the plot


plt.plot(months, sales, marker='o', color='blue')
plt.title("Monthly Sales Report")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.grid(True)
plt.tight_layout()

# Display the plot


plt.show()

# Save the plot


plt.savefig("sales_plot.png")

📦 Bonus: Pandas Version (Cleaner)


import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('data.csv')
plt.plot(df['Month'], df['Sales'], marker='o')
plt.title("Monthly Sales Report")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.grid(True)
plt.tight_layout()
plt.show()

📌 Output
● A line graph with months on the X-axis and sales on the Y-axis

● Optional: saved as sales_plot.png

📄 RESUME PROJECT DESCRIPTION 🧾


Gowtham SB
www.linkedin.com/in/sbgowtham/ Instagram - @dataengineeringtamil
Project: Data Visualization using Python and Matplotlib

- Developed a Python-based data visualization script to read sales data from CSV files and
generate dynamic line plots using matplotlib.
- Automated the generation of monthly sales graphs, including labels, markers, grid, and saving
as images.
- Gained hands-on experience with CSV handling, matplotlib styling, and exporting
visualizations for reports.

💬 HOW TO EXPLAIN IN INTERVIEW


➤ Q: Can you explain your matplotlib project?
A:

Sure! I created a mini data visualization tool using Python. It reads a CSV file with
sales data using the csv or pandas library and then uses matplotlib to plot a
clean, labeled line graph. I added customization like axis labels, markers, grids, and
saved the final chart as an image file. This helped me understand both CSV parsing
and real-time plotting automation.

➤ Q: Why did you choose matplotlib?


A: I chose matplotlib because it's simple yet powerful. For basic to advanced graphs, it offers
complete control over styling, annotations, and exporting. It also integrates well with pandas for
handling data frames.

➤ Q: Can you improve this further?

A:

Yes! I can add dynamic user inputs, generate multiple chart types (bar, scatter,
etc.), or even create a dashboard using streamlit or dash to make it interactive.

About the Author


Gowtham SB is a Data Engineering expert, educator, and content creator with a
passion for big data technologies, as well as cloud and Gen AI . With years of
experience in the field, he has worked extensively with cloud platforms, distributed
Gowtham SB
www.linkedin.com/in/sbgowtham/ Instagram - @dataengineeringtamil
systems, and data pipelines, helping professionals and aspiring engineers master the
art of data engineering.

Beyond his technical expertise, Gowtham is a renowned mentor and speaker, sharing
his insights through engaging content on YouTube and LinkedIn. He has built one of
the largest Tamil Data Engineering communities, guiding thousands of learners to
excel in their careers.

Through his deep industry knowledge and hands-on approach, Gowtham continues to
bridge the gap between learning and real-world implementation, empowering
individuals to build scalable, high-performance data solutions.

𝐒𝐨𝐜𝐢𝐚𝐥𝐬

𝐘𝐨𝐮𝐓𝐮𝐛𝐞 - https://www.youtube.com/@dataengineeringvideos

𝐈𝐧𝐬𝐭𝐚𝐠𝐫𝐚𝐦 - https://instagram.com/dataengineeringtamil

𝐈𝐧𝐬𝐭𝐚𝐠𝐫𝐚𝐦 - https://instagram.com/thedatatech.in

𝐂𝐨𝐧𝐧𝐞𝐜𝐭 𝐟𝐨𝐫 𝟏:𝟏 - https://topmate.io/dataengineering/

𝐋𝐢𝐧𝐤𝐞𝐝𝐈𝐧 - https://www.linkedin.com/in/sbgowtham/

𝐖𝐞𝐛𝐬𝐢𝐭𝐞 - https://codewithgowtham.blogspot.com

𝐆𝐢𝐭𝐇𝐮𝐛 - http://github.com/Gowthamdataengineer

𝐖𝐡𝐚𝐭𝐬 𝐀𝐩𝐩 - https://lnkd.in/g5JrHw8q

𝐄𝐦𝐚𝐢𝐥 - [email protected]

𝐀𝐥𝐥 𝐌𝐲 𝐒𝐨𝐜𝐢𝐚𝐥𝐬 - https://lnkd.in/gf8k3aCH

You might also like