Modern scientific visualization often requires coloring two- or three-dimensional maps according to some other dimension of the data. An aerodynamic simulation might color the flow of fluid around and a three-dimensional airfoil according to a fourth dimension such as velocity. Here, we'll use examples from analytical electron microscopy, where two- or three-dimensional maps will be colored accoring to additional dimensions, such as intensity of X-ray signals at each pixel, or calculated weight or atom percent of a constituent at each pixel.
<br><br>
Here, we have three datasets derived from a single scanning electron microscope (SEM) X-ray spectrum image. The datasets are: <br>
1.`counts`: Raw number of X-ray counts at each pixel. This is an example of a strictly non-negative, but smoothly varying, dataset.<br>
2.`svd`: A single abundance map derived from singular value decomposition (aka principal component analysis) of the dataset. This contains smoothly varying data with positive and negative values of roughly the same magnitude. (*) <br>
3.`kmeans`: A cluster assignment map dervied from K-means clustering of the data. This is strictly positive data, but mapped to discrete integer values (0, 1, 2...) rather than smoothly varying. <br>
<br>
These three maps are representative, then, of many types of higher-dimensional data presented as false color maps. We will illustrate using four types of colormaps: (1) smoothly varying and perceptually uniform; (2) diverging; (3) discrete or qualitative; and (4) rainbow.
<br>
<br>
(*) Those familiar with SVD might notice the values are too large to be an orthonormal basis set, as SVD requires. This abundance map is actually the relevant left singular vector multiplied by its associated singular value, resulting in the approximate range -7 to +7.
%% Cell type:markdown id: tags:
### Imports:
%% Cell type:code id: tags:
``` python
importnumpyasnp
importmatplotlib.pyplotasplt
importh5py
importstring
```
%% Cell type:markdown id: tags:
### Import the data
We have stored the three datasets into an HDF5-type file. HDF5 is the most versatile file format for storing and transferring scientific data and we recommend it for essentially any application that involves storing one or more numeric array.
%% Cell type:code id: tags:
``` python
withh5py.File('colormap_images.h5','r')asfh:
print(list(fh.keys()))
svd=np.array(fh['abundances'])
kmeans=np.array(fh['clusters'])
counts=np.array(fh['x-ray_counts'])
```
%% Output
['abundances', 'clusters', 'x-ray_counts']
%% Cell type:markdown id: tags:
### Prepare the data we will need to generate the figure