Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Master Data Science with Python

Lesson 31 of 60 · python

Matplotlib Basics: Plotting with Python

Duration: 15 minutes

Matplotlib Basics

Matplotlib is the foundational plotting library in Python. It works well for static images and integrates tightly with Pandas.

Importing the library

import matplotlib.pyplot as plt

Simple line plot

x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
plt.plot(x, y, marker='o', linestyle='-')
plt.title('Simple Line Plot')
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()

Saving a figure

plt.savefig('images/line_plot.png', dpi=300, bbox_inches='tight')

The Figure and Axes objects

fig, ax = plt.subplots(figsize=(6,4))
ax.plot(x, y, color='purple')
ax.set_title('Figure & Axes Example')
plt.show()

Info

Use the %matplotlib inline magic in Jupyter to embed plots directly in the notebook.

Previous: Pandas Project: Titanic Data AnalysisNext: Line, Scatter, and Bar Charts