📅  最后修改于: 2023-12-03 14:44:12.879000             🧑  作者: Mango
Matplotlib is a data visualization library in Python. Pyplot is a subpackage in matplotlib that provides a convenient interface for creating plots and charts. The pyplot API provides a way to create and customize plots with minimal code.
You can install Matplotlib using pip package manager. Open your terminal and type the following command:
pip install matplotlib
Pyplot provides a convenient API to create a plot with a single line of code. Here is an example:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 30, 40]
plt.plot(x, y)
plt.show()
The plot
function creates a line plot with x
as the x-axis and y
as the y-axis. The show
function displays the plot.
You can customize various aspects of a plot using pyplot. Here are a few examples:
plt.plot(x, y)
plt.title("My Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()
plt.plot(x, y, linestyle="dashed", color="red")
plt.show()
plt.plot(x, y, marker="o")
plt.show()
y2 = [15, 25, 35, 45]
plt.plot(x, y)
plt.plot(x, y2)
plt.show()
In this tutorial, we learned about the Matplotlib-Pyplot API, which provides a convenient way to create and customize plots in Python. We covered how to install Matplotlib, how to create a basic line plot, and how to customize various aspects of the plot using pyplot. With pyplot, you can create impressive plots with minimal effort.