Making Labels


How do you make nicely formatted labels?


Say we have the following trivial list of levels:

>>> levels = vcs.mkevenlevels(-1e-5, 1e-5, 2)
>>> levels
[-1.0000000000000001e-05, 0.0, 1.0000000000000001e-05]

We want to format these values so they look "nice." The mklabels command does the trick:

>>> print vcs.mklabels(levels, output='list')
['-1E-5', '0E-5', '1E-5']

However, mklabels has an even handier use: given a list of levels, it will automatically create the dictionary required by the graphics method attributes that store the x- and y-axis tick labels. To do so, just set the output keyword to 'dict' (or leave it out of the calling line, as 'dict' is the keyword's default value):

>>> labels = vcs.mklabels(levels, output='list')
>>> print labels
{0.0: '0E-5', 1.0000000000000001e-05: '1E-5', -1.0000000000000001e-05: '-1E-5'}

Say you have an xvsy graphics method xy_gm and you want labels to be your x-axis tick labels. Just type:

xy_gm.xticlabels1 = labels

Notes: This discussion applies to CDAT 3.3.

Return to the Tips and Examples index page.

Updated: December 5, 2003 by Johnny Lin <email address>. License.