Formation
90 min read
Data Visualization
π¦ Visualization with Matplotlib
Learning objectives
π― Objectives:\n
1Create line plots\n2. Create bar charts\n3. Create histograms\n4. Customize plots
Introduction
π Matplotlib is the most widely used visualization library in Python.
Theoretical content
Matplotlib:\n
PYTHON
\nimport matplotlib.pyplot as plt\nplt.plot([1,2,3], [4,5,6])\nplt.show()\nPractical examples
π» Example: Sales chart\n
PYTHON
\nimport matplotlib.pyplot as plt\nplt.plot(["Jan", "Feb"], [1000, 1200])\nplt.show()\nBest practices
1Always import plt\nβ
2. Use figure() for size\nβ
3. Add titles and labels\nβ
4. Use grid() for readability\nβ
5. tight_layout() to avoid overlap
Common pitfalls
Forgetting plt.show()\n
Always call plt.show()
Summary
plot(): line plot\nβ
bar(): bar chart\nβ
hist(): histogram\nβ
title(), xlabel(), ylabel(): labels\nβ
legend(): legend\nβ
grid(): grid\nβ
show(): display
Additional resources
π matplotlib.org/stable/tutorials/index.html