Module 3 of 21 · Data Visualization — Matplotlib, Seaborn, Plotly, EDA Charts, Dashboards · Beginner

Basic Plots with Matplotlib

Duration: 5 min

This module introduces the basics of creating plots using Matplotlib, a powerful plotting library in Python. Understanding how to visualize data is crucial for data analysis and presentation, as it allows for better insights and communication of findings.

Creating a Simple Line Plot

A line plot is one of the most basic and commonly used types of plots. It is used to display the trend of data over time or another continuous variable. In Matplotlib, you can create a line plot using the plot function.

import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]

# Creating a line plot
plt.plot(x, y)

# Adding title and labels
plt.title('Simple Line Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')

# Displaying the plot
plt.show()

Try it in Google Colab: Open in Colab

A line plot with points at (1,2), (2,3), (3,5), (4,7), and (5,11), titled 'Simple Line Plot' with labeled axes.

Customizing Plot Appearance

Matplotlib allows extensive customization of plot appearance, including line styles, colors, markers, and more. This can be done by passing additional arguments to the plot function or using other functions like xlabel, ylabel, and title.

import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]

# Creating a customized line plot
plt.plot(x, y, linestyle='--', color='r', marker='o')

# Adding title and labels
plt.title('Customized Line Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')

# Displaying the plot
plt.show()

💡 Tip: When customizing plots, experiment with different line styles, colors, and markers to find the best representation for your data. Remember that clarity and readability are key.

❓ What function is used to create a line plot in Matplotlib?

❓ Which argument can be used to change the line style in a Matplotlib plot?

← Previous Continue interactively → Next →

Related Courses