Creating your own color tableYou can create your own color table, and place it where PyNGL can load it directly or keep it in your own personal directory.
Color tables in PyNGL can only have up to 256 colors, and 2 of these colors are taken up by the foreground and background colors. When you create your own color table, the foreground and background colors will automatically be added and set to black and white respectively (unless you set the wkForegroundColor and wkBackgroundColor resources in your script or resource file).
Generate RGB tripletsFirst, you need to generate the red/green/blue (RGB) triplets that represent each color in your color table. Do not generate triplets for the foreground and background colors as PyNGL will automatically set these for you.
RGB triplets in this context are integers from 0 to 255, where the greater the number, the higher concentration of that color. Here are some sample RGB triplets and their corresponding color:
|Red||Green||Blue||Resultant color||Red||Green||Blue||Resultant color|
RGB triplets with all three RGB values equal create varying shades of gray. For some further examples of colors associated with RGB triplets, see the color table in the color4 example and its output (or execute "pynglex color4").
Create file with triplets in itDecide what you are going to call this color table, and create a file called xxxx.rgb, where xxxx is the color table name. At the beginning of this file, add the two lines:
ncolors=n # r g bwhere n is the number of RGB triplets you have in the file.
Immediately following these two lines, put the RGB triplets in this file with one RGB triplet per line. For example:
160 32 240 0 0 180Here's a sample color table with 8 colors:
ncolors=8 # r g b 160 32 240 0 0 180 60 100 230 120 155 242 176 224 230 46 139 87 100 225 0 210 255 47Once you add the above color table to PyNGL, it will actually have 10 colors, as the foreground and background colors will be added.
Move file to appropriate directoryTo have PyNGL automatically see this color table like it does the other color tables, move the file xxxx.rgb to the directory $PYTHONPATH/lib/pythonx.y/site-packages/PyNGL/ncarg/colormaps/.
Otherwise, if you want to keep the file in a personal directory, then you need to set the environment variable PYNGL_COLORMAPS to point to the full path of this directory. Note that once you do this, PyNGL will no longer see the other color tables that reside in the standard location.
Here are some examples of setting your environment variable for csh and bash environments:
setenv PYNGL_COLORMAPS /home/haley/colormapsbash:
Test your new color tableTo test that your new color table has been created correctly and that PyNGL can see it, run the following script (replacing xxxx with the name you gave the color table):
import Ngl wkres = Ngl.Resources() wkres.wkColorMap = "xxxx" wks = Ngl.open_wks("x11","test",wkres) Ngl.draw_colormap(wks) Ngl.end()The above script should open an X11 window, load your new color table, and draw it. Note that color indices 0 and 1 will represent the background and foreground colors, respectively.