📅  最后修改于: 2023-12-03 15:03:55.787000             🧑  作者: Mango
Pyplot is a module in the Matplotlib library, which is used for creating static, animated, and interactive visualizations in Python. It is a collection of functions that helps in creating a variety of charts such as histograms, bar charts, scatterplots, etc.
!pip install matplotlib
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, 10, 0.1)
y = np.sin(x)
plt.plot(x, y)
plt.show()
plt.plot(x, y, label="sin(x)")
plt.xlabel("x")
plt.ylabel("y")
plt.title("Sine Function")
plt.legend()
plt.show()
y1 = np.sin(x)
y2 = np.cos(x)
plt.subplot(2, 1, 1)
plt.plot(x, y1)
plt.title('Sine Function')
plt.subplot(2, 1, 2)
plt.plot(x, y2)
plt.title('Cosine Function')
plt.tight_layout()
plt.show()
plt.savefig('sine.png')
In this article, we have discussed the basics of Pyplot module in Python. We saw how to install it, import it and use it to create basic plots. We also added labels, title, and legends to the plots, created multiple plots in a single figure and saved the plots. Pyplot is a powerful tool for visualizing data and is widely used in scientific and data visualization applications.