It is common to use matplotlib and cartopy to visualize meteorological data with a map using Python. The procedure for building the environment for that with Anaconda (Miniconda) is described below. The OS version you have is macOS Catalina 10.15.7.
Anaconda is a Python distribution that allows you to manage packages and create virtual environments. You can do the same thing with pyenv and pip, but I'll use this because it's convenient because you can install dependent programs at the same time.
Miniconda is the minimum configuration version of Anaconda. Since there are few packages installed at the beginning and there is an advantage that it does not take up disk space, we will introduce this.
#Download installer
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
#Install interactively
bash Miniconda3-latest-MacOSX-x86_64.sh
You can refer to other articles for how to use it, but you can use the conda
command to manage packages for each virtual environment. If the prompt says something like (base) $
, it means you are in the anaconda virtual environment called base
. You can install the package in the base
environment, but here we will create a new environment called cartopy-env
.
conda create -n cartopy-env python=3.9
Just creating a virtual environment with conda create
does not include python
, so make sure to install Python by specifying the version. Here, I specified the latest version 3.9 at the time of writing.
Hit conda activate
to switch the virtual environment.
conda activate cartopy-env
It's OK if the prompt shows something like (cartopy-env) $
.
Next, install the required Python packages. For example, to install numpy
for scientific calculations, use the following command.
conda install -c conda-forge numpy
Since the same package is provided by multiple repositories in conda, the -c
option specifies which repository to install from (here, conda-forge
). You can search for what packages are available at https://anaconda.org/. Basically, you can choose the conda-forge
repository.
Now let's install the other necessary items. You can specify multiple package names separated by spaces.
conda install -c conda-forge scipy netcdf4 matplotlib cartopy
You can check the version of the installed package with conda list
. Here's a rough description of the major package versions installed in your environment.
--numpy (1.19.4)
: Library for scientific computing
--scipy (1.5.3)
: A library for scientific computing, including functions not found in numpy
.
--netcdf4 (1.5.4)
: Required to read and write netCDF format files. Recently, it seems that xarray
is sometimes used as an equivalent.
--matplotlib (3.3.3)
: Required for drawing diagrams
--cartopy (0.18.0)
: Required to draw a map with matplotlib
That's all for the explanation.