How to Install Matplotlib in Visual Studio Code (VS Code) | Step-by-Step Guide
Want to create *beautiful data visualizations* using Python in *Visual Studio Code (VS Code)**? 📊 **Matplotlib* is a powerful Python library used for plotting *graphs, charts, and visualizations**. In this tutorial, we'll show you how to **install Matplotlib in VS Code* and create your first plot! 🚀
Whether you're a beginner or an experienced coder, this step-by-step guide will help you set up Matplotlib and troubleshoot common installation errors.
---
🔹 *What You’ll Learn in This Video:*
✅ How to *install Matplotlib using pip* in VS Code
✅ Setting up a *virtual environment (venv)* for Python projects
✅ Running Python scripts in VS Code
✅ Creating a *basic Matplotlib plot*
✅ Fixing common Matplotlib installation errors
---
*🚀 Step-by-Step Guide to Installing Matplotlib in VS Code*
#### *1️⃣ Install Python and VS Code*
🔹 Ensure you have *Python installed* on your system. Check by running:
```bash
python --version
```
If Python is not installed, download it from [https://www.python.org/downloads/](https://www.python.org/downloads/) and install it.
🔹 Download and install *VS Code* from [https://code.visualstudio.com/](https://code.visualstudio.com/).
---
#### *2️⃣ Install Matplotlib Using PIP in VS Code*
Open *VS Code Terminal* and run:
```bash
pip install matplotlib
```
✅ This will install Matplotlib along with any required dependencies.
---
#### *3️⃣ Verify Installation*
After installation, check if Matplotlib is installed correctly:
```python
import matplotlib
print(matplotlib.__version__) # This will print the installed Matplotlib version
```
If this runs without errors, Matplotlib is installed successfully! ✅
---
#### *4️⃣ Create a Simple Plot in VS Code*
Create a new Python file in VS Code (**example.py**) and add this code:
```python
import matplotlib.pyplot as plt
Sample Data
x = [1, 2, 3, 4, 5]
y = [10, 20, 25, 30, 40]
Create a Line Plot
plt.plot(x, y, marker='o', linestyle='-', color='b', label="Line Chart")
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.title("Simple Line Plot in Matplotlib")
plt.legend()
plt.show()
```
💡 *Save the file and run it in VS Code's terminal* using:
```bash
python example.py
```
A *graph window* will open displaying the plot! 🎉
---
🔹 *Fixing Common Errors*
*Error: "matplotlib not found"*
🔹 Ensure you installed Matplotlib in the correct Python environment:
```bash
pip install --user matplotlib
```
*Plots Not Displaying in VS Code?*
🔹 Add this line before `plt.show()`:
```python
plt.savefig("plot.png") # Saves the plot as an image
```
*Using Jupyter Notebook in VS Code?*
🔹 Install Jupyter and use Matplotlib inline:
```bash
pip install jupyter
```
Then in the Jupyter cell:
```python
%matplotlib inline
```
---
*📌 Useful Links:*
🔗 Matplotlib Documentation: [https://matplotlib.org/stable/content...](https://matplotlib.org/stable/content...)
🔗 VS Code Python Extension: [https://marketplace.visualstudio.com/...](https://marketplace.visualstudio.com/...)
🚀 *Have Questions?* Drop a comment below! If this tutorial helped you, *LIKE* 👍 this video, *SUBSCRIBE* 🔔 for more Python and VS Code tutorials, and *SHARE* with your friends!
📌 *Hashtags:*
#Matplotlib #Python #VisualStudioCode #VSCODE #DataVisualization #PythonPlots #DataScience #PythonProgramming #MachineLearning
On this page of the site you can watch the video online How to Install Matplotlib in Visual Studio Code with a duration of hours minute second in good quality, which was uploaded by the user ProgrammingKnowledge 21 March 2025, share the link with friends and acquaintances, this video has already been watched 36,838 times on youtube and it was liked by 259 viewers. Enjoy your viewing!