Menu
Matplotlib
What is Matplotlib?
- Matplotlib is a Python plotting library used for creating static, animated, and interactive visualizations.
- It can be used for plotting graphs such as line plots, bar charts, histograms, and more.
- Matplotlib was created by John D. Hunter in 2003 and has become a core plotting library in Python.
- Matplotlib works well with NumPy and Pandas data structures.
At First we downlode the library of Matplotlib
pip install matplotlib
Matplotlib Basic Example
import matplotlib.pyplot as plt
# Create data
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
# Create a figure
plt.figure(figsize=(10, 6))
# Plot the data
plt.plot(x, y, label='y = x^2')
# Set title, labels, and limits
plt.title('Basic Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.xlim(0, 6)
plt.ylim(0, 30)
# Add ticks
plt.xticks([1, 2, 3, 4, 5])
plt.yticks([0, 5, 10, 15, 20, 25])
# Add grid, legend, and show the plot
plt.grid(True)
plt.legend()
plt.show()
This code demonstrates how to use various `matplotlib` functions:
Conclusion
Matplotlib is a very versatile plotting library that can be used for a variety of visualizations. It is essential for data visualization in Python and can be customized to meet specific needs, including adding titles, labels, legends, and modifying axes and grid properties.
No comments yet. Be the first to comment!