Generating a Portraet diagram

The GlecklerPlot class provides functionality to generate a Portraet diagram as introduced by Gleckler et al. (2008). The class is very usefull if you want to vizualize e.g. different statistical results.

Single variable


In [1]:
%matplotlib inline
from pycmbs.plots import GlecklerPlot

G = GlecklerPlot()
#register first models (these fill become the rows in the plot)
G.add_model('echam5')
G.add_model('mpi-esm-LR')
G.add_model('mpi-esm-MR')

#then register variables (these become the columns in the plot)
G.add_variable('ta')

#after that you can add values to be plotted; pos=1 mean that result is plotted in upper triangle
# you can specify up to 4 positions
# assign values you want to plot
G.add_data('ta','echam5',0.2,pos=1)
G.add_data('ta','mpi-esm-LR',0.5,pos=1)
G.add_data('ta','mpi-esm-MR',1.3,pos=1)

# do the plot
G.plot()

# save figure to file
#G.fig.savefig('filename.png')


/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/__init__.py:1155: UserWarning:  This call to matplotlib.use() has no effect
because the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

  warnings.warn(_use_error_msg)
Out[1]:

Note that two figures might be plotted here. This is just a problem with the ipython notebook used and not a problem with the actual GlecklerPlot!

Multiple variables


In [2]:
del G
G = GlecklerPlot()
#register first models (these fill become the rows in the plot)
G.add_model('echam5')
G.add_model('mpi-esm-LR')
G.add_model('mpi-esm-MR')
#then register variables (these become the columns in the plot)
G.add_variable('ta')
G.add_variable('P')
G.add_variable('sea_ice')
#after that you can add values to be plotted; pos=1 mean that result is plotted in upper triangle
# you can specify up to 4 positions
G.add_data('ta','echam5',0.5,pos=1)
G.add_data('ta','mpi-esm-LR',0.3,pos=1)

G.add_data('P','echam5',0.25,pos=1)
G.add_data('P','mpi-esm-MR',-0.25,pos=2)
G.add_data('P','mpi-esm-MR',1.3,pos=1)
G.add_data('P','mpi-esm-LR',0.3,pos=1)
G.add_data('P','mpi-esm-LR',0.6,pos=2)

# random numbers are generated here using numpy
import numpy as np
G.add_data('sea_ice','echam5',np.random.random(1),pos=1)
G.add_data('sea_ice','echam5',np.random.random(1),pos=2)
G.add_data('sea_ice','echam5',np.random.random(1),pos=3)
G.add_data('sea_ice','echam5',np.random.random(1),pos=4)

G.add_data('sea_ice','mpi-esm-MR',np.random.random(1),pos=1)
G.add_data('sea_ice','mpi-esm-MR',np.random.random(1),pos=2)
G.add_data('sea_ice','mpi-esm-MR',np.random.random(1),pos=3)
G.add_data('sea_ice','mpi-esm-MR',np.random.random(1),pos=4)

G.add_data('sea_ice','mpi-esm-LR',np.random.random(1),pos=1)
G.add_data('sea_ice','mpi-esm-LR',np.random.random(1),pos=2)
G.add_data('sea_ice','mpi-esm-LR',np.random.random(1),pos=3)
G.add_data('sea_ice','mpi-esm-LR',np.random.random(1),pos=4)

G.plot() #do plot


/usr/local/lib/python2.7/dist-packages/numpy/core/_methods.py:59: RuntimeWarning: Mean of empty slice.
  warnings.warn("Mean of empty slice.", RuntimeWarning)
/usr/local/lib/python2.7/dist-packages/numpy/core/_methods.py:71: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)
Out[2]:

More help? Look at the help of the plot function