Before we can start creating plots, we need to make sure your computer is ready with the necessary tools. This involves setting up a Python environment that includes the Matplotlib and Seaborn libraries, along with their common companions like NumPy and Pandas.
Think of a Python environment as a dedicated workspace for your project. It keeps the specific versions of libraries your project needs separate from other projects, preventing conflicts. For data science and visualization tasks, managing these libraries and their dependencies can sometimes be tricky, but thankfully, we have tools to simplify this process.
One of the most popular ways to manage Python environments and packages for data science is Anaconda (or its lighter-weight sibling, Miniconda). Anaconda is a distribution that comes bundled with Python, a powerful environment and package manager called conda
, and many commonly used data science libraries pre-installed. This makes setup relatively straightforward.
Why Anaconda?
conda
is excellent at managing complex dependencies between libraries, which is common in scientific computing.Steps (General Guide):
viz_env
and include Python, Matplotlib, Seaborn, Pandas, NumPy, and JupyterLab (a useful tool for interactive plotting):
conda create --name viz_env python=3.9 matplotlib seaborn pandas numpy jupyterlab
You might be prompted to proceed (y/n
); type y
and press Enter. Note: You can choose a different Python version if needed, but 3.9 or higher is generally recommended.conda activate viz_env
Your terminal prompt should now show (viz_env)
at the beginning, indicating the environment is active.If you prefer not to use Anaconda, you can use Python's built-in tools: venv
for creating virtual environments and pip
for installing packages. This approach is often favored by software developers and keeps installations minimal.
Why pip and venv?
venv
comes standard with Python 3.3+. pip
is the standard Python package installer.Steps (General Guide):
pip
usually comes installed with Python. You can check your Python version by typing python --version
or python3 --version
in your terminal.python -m venv viz_env
This creates a folder named viz_env
containing a copy of the Python interpreter and a place to install libraries.source viz_env/bin/activate
viz_env\Scripts\activate
Your terminal prompt should change to indicate the active environment (often showing (viz_env)
).pip
to install the required packages:
pip install matplotlib seaborn pandas numpy jupyterlab
While both methods work, we recommend using Anaconda for this course, especially if you are new to Python environments. Its ability to handle the complex interdependencies often found in data science libraries makes the setup process smoother.
Once you have installed the libraries using either method and activated your environment (viz_env
), you can perform a quick check. Start a Python interpreter by typing python
in your activated terminal, or launch JupyterLab by typing jupyter lab
.
In the Python prompt or a Jupyter Notebook cell, try importing the libraries:
import matplotlib
import seaborn
import pandas
import numpy
print("Libraries imported successfully!")
print(f"Matplotlib version: {matplotlib.__version__}")
print(f"Seaborn version: {seaborn.__version__}")
print(f"Pandas version: {pandas.__version__}")
print(f"NumPy version: {numpy.__version__}")
If this code runs without any ImportError
messages and prints the versions, your environment is correctly set up, and you're ready to move on to importing these libraries into your scripts and creating your first plot!
© 2025 ApX Machine Learning