-->

Python - Matplotlib Pyplot Part 1: Basic Plotting with Pyplot

Pyplot's core functionality revolves around creating simple plots and customizing them.

Examples and Explanation

Basic Line Plot

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]

y = [1, 4, 9, 16]

plt.plot(x, y)

plt.title("Basic Line Plot")

plt.show()

Explanation: The plot() function is the simplest way to create a line chart. The show() function displays the figure.

Adding Labels

plt.plot(x, y)

plt.xlabel("X-axis")

plt.ylabel("Y-axis")

plt.title("Line Plot with Labels")

plt.show()

Explanation: Adding labels and titles enhances the readability of the plot.

Customizing Line Styles

plt.plot(x, y, linestyle='--', color='red', marker='o')

plt.title("Customized Line Plot")

plt.show()

Explanation: You can customize line styles, colors, and markers for better visualization.