Appendix A: Python Visualization Setup Guide
This appendix walks you through setting up a complete Python data visualization environment. Whether you are starting from scratch or adding visualization packages to an existing workflow, follow the steps below to get every library used in this book installed and configured.
Choosing a Python Distribution
You have two mainstream options for managing Python installations:
Anaconda / Miniconda (recommended for this book). Conda handles both Python packages and non-Python system dependencies (GDAL, PROJ, and GEOS for geospatial work; C libraries for HDF5). If your work involves geospatial visualization (Chapter 23) or scientific computing (Chapter 27), conda will save you hours of troubleshooting compiled dependencies.
- Download Miniconda (lightweight) from https://docs.conda.io/en/latest/miniconda.html
- Or download the full Anaconda distribution from https://www.anaconda.com/download
pip + venv (lighter-weight alternative). If you prefer a minimal footprint and do not need geospatial libraries, standard pip with virtual environments works well. Use python -m venv to create isolated environments.
Creating an Environment
With conda:
conda create -n dataviz python=3.11 -y
conda activate dataviz
With pip:
python -m venv dataviz-env
source dataviz-env/bin/activate # macOS/Linux
dataviz-env\Scripts\activate # Windows
Core Packages
Install these packages first. They are used in nearly every chapter.
| Package | Purpose | Chapters |
|---|---|---|
| matplotlib | Foundation plotting library | 10--15, used throughout |
| seaborn | Statistical visualization built on matplotlib | 16--19 |
| pandas | Data manipulation, integrates with all plotting libs | All |
| numpy | Numerical arrays, math operations | All |
| jupyter | Interactive notebooks for exploration | All |
# conda
conda install matplotlib seaborn pandas numpy jupyterlab -y
# pip
pip install matplotlib seaborn pandas numpy jupyterlab
Interactive Visualization Packages
These libraries produce browser-based, interactive charts.
| Package | Purpose | Chapters |
|---|---|---|
| plotly | Interactive charts (Express and Graph Objects) | 20--21 |
| altair | Declarative visualization based on Vega-Lite | 22 |
# conda
conda install -c conda-forge plotly altair vega_datasets -y
# pip
pip install plotly altair vega_datasets
For Plotly charts to render inside JupyterLab, you may also need:
pip install jupyterlab-plotly
Dashboard and Reporting Packages
| Package | Purpose | Chapters |
|---|---|---|
| streamlit | Rapid dashboard prototyping | 29 |
| dash | Production-grade dashboards (Plotly ecosystem) | 30 |
| fpdf2 | Programmatic PDF generation | 31 |
| python-pptx | PowerPoint slide generation | 31 |
pip install streamlit dash fpdf2 python-pptx
Streamlit and Dash are pip-only for the latest versions. Conda-forge packages exist but may lag behind.
Specialized Visualization Packages
| Package | Purpose | Chapters |
|---|---|---|
| geopandas | Geospatial data structures and plotting | 23 |
| folium | Leaflet-based interactive maps | 23 |
| networkx | Graph/network data structures and algorithms | 24 |
| pyvis | Interactive network visualization | 24 |
| datashader | Rendering millions-to-billions of points | 28 |
| holoviews | High-level declarative interface for datashader | 28 |
| wordcloud | Word cloud generation | 26 |
| scipy | Scientific computing, statistical tests | 27 |
For geospatial work, conda handles binary dependencies far more reliably:
conda install -c conda-forge geopandas folium -y
For the remaining specialized packages:
pip install networkx pyvis datashader holoviews wordcloud scipy
One-Shot Install
If you want everything at once, the repository includes a requirements.txt file:
pip install -r requirements.txt
Or with conda, use the provided environment.yml:
conda env create -f environment.yml
conda activate dataviz
Jupyter Setup
JupyterLab is the recommended interface for working through this book.
jupyter lab
Useful Extensions
- jupyterlab-plotly -- Renders Plotly figures inline.
- jupyterlab-code-formatter -- Auto-formats code with Black or isort.
- jupyterlab-git -- Git integration inside JupyterLab.
Install them via:
pip install jupyterlab-plotly jupyterlab-code-formatter jupyterlab-git
Notebook Best Practices
- Set matplotlib to inline mode at the top of each notebook:
%matplotlib inline - For higher-resolution figures in notebooks, add:
%config InlineBackend.figure_format = 'retina' - Use
%load_ext autoreloadand%autoreload 2when developing helper modules.
IDE Recommendations
If you prefer an IDE over Jupyter for script-based work:
- VS Code with the Python and Jupyter extensions. Supports inline figure rendering, variable exploration, and integrated terminals. The best all-around choice for mixed notebook and script workflows.
- PyCharm Professional includes built-in Scientific Mode with inline matplotlib rendering and a DataFrame viewer. The Community edition lacks notebook support.
- Spyder ships with Anaconda and provides a MATLAB-like experience with a variable explorer and inline plot pane. Good for scientists who prefer a traditional IDE layout.
Verifying Your Installation
Run this script to confirm that all key packages import correctly:
import matplotlib; print(f"matplotlib {matplotlib.__version__}")
import seaborn; print(f"seaborn {seaborn.__version__}")
import plotly; print(f"plotly {plotly.__version__}")
import altair; print(f"altair {altair.__version__}")
import pandas; print(f"pandas {pandas.__version__}")
import numpy; print(f"numpy {numpy.__version__}")
# Optional -- will raise ImportError if not installed
try:
import geopandas; print(f"geopandas {geopandas.__version__}")
except ImportError:
print("geopandas not installed (needed for Ch 23)")
try:
import streamlit; print(f"streamlit {streamlit.__version__}")
except ImportError:
print("streamlit not installed (needed for Ch 29)")
print("\nAll core packages loaded successfully.")
Troubleshooting Common Issues
matplotlib figures not displaying. Make sure you run %matplotlib inline in Jupyter or call plt.show() in scripts.
Plotly blank output in JupyterLab. Install jupyterlab-plotly and restart the lab server.
geopandas installation fails with pip. Use conda instead: conda install -c conda-forge geopandas. The C library dependencies (GDAL, PROJ, GEOS) are pre-built in conda.
Conflicting package versions. Always work inside a dedicated virtual environment or conda environment. Avoid installing visualization libraries into your system Python.
Permission errors on Windows. Run your terminal as Administrator or use the --user flag: pip install --user matplotlib.
Apple Silicon (M1/M2/M3) compatibility. Conda-forge packages are built for ARM64. If a package installs but crashes, ensure you are using a native ARM conda rather than an x86 Rosetta environment.