Visualizing 2D data

Colormaps are used to map quantities stored at each point of a (discretized) surface to colours. Colours live in a 3D space. 2D data may contain metric or form information (or both). How can we choose a good colormap?

  • Perception
  • Intuition
  • Convention

By default, we want to use a sequential colormap (not assuming anything about the structure of our data).


In [1]:
import pickle

In [2]:
data = pickle.load(open('data/correlation_map.pkl', 'rb'))

In [3]:
data.keys()


Out[3]:
dict_keys(['emission energy', 'excitation energy', 'correlation'])

In [4]:
type(data['excitation energy'])


Out[4]:
numpy.ndarray

In [5]:
data['excitation energy'].shape


Out[5]:
(135,)

In [6]:
data['correlation'].shape


Out[6]:
(55, 135)

In [7]:
import matplotlib
%matplotlib inline
matplotlib.style.use('ggplot')
import matplotlib.pyplot as plt

In [8]:
plt.imshow(data['correlation'])


Out[8]:
<matplotlib.image.AxesImage at 0x7fbe87271860>

Are we dealing with form or metric information here?


In [9]:
matplotlib.__version__


Out[9]:
'1.5.dev1'

In [10]:
from matplotlib.cm import magma, inferno, plasma, viridis
# from colormaps import magma, inferno, plasma, viridis

In [11]:
correlation = data['correlation']
excitation = data['excitation energy']
emission = data['emission energy']

In [12]:
plt.imshow(correlation,
           origin='lower',
           cmap=magma)


Out[12]:
<matplotlib.image.AxesImage at 0x7fbe871a4550>

In [13]:
plt.imshow(correlation,
           origin='lower',
           extent=[excitation.min(), excitation.max(), emission.min(), emission.max()],
           cmap=magma)


Out[13]:
<matplotlib.image.AxesImage at 0x7fbe8710b8d0>

In [14]:
f, ax = plt.subplots(1, 1, figsize=(5, 5))
map0 = ax.imshow(correlation,
          origin='lower',
          extent=[excitation.min(), excitation.max(), emission.min(), emission.max()],
          cmap=magma)
ax.plot(excitation, excitation)
ax.set_xlabel('Excitation Energy (eV)')
f.colorbar(map0, ax=ax)


Out[14]:
<matplotlib.colorbar.Colorbar at 0x7fbe870446a0>

Revise and edit to best convey the scientific result.


In [15]:
f, ax = plt.subplots(1, 1, figsize=(5, 5))
ax.imshow(correlation,
          origin='lower',
          extent=[excitation.min(), excitation.max(), emission.min(), emission.max()],
          cmap=viridis)
ax.plot(excitation, excitation)
ax.set_xlabel('Excitation Energy (eV)')


Out[15]:
<matplotlib.text.Text at 0x7fbe86fff470>

What about using the new default colormap (above)?