Search code examples
xmgrace

More colors in xmgrace


I am using a simple batch script to make a simple 2D graphs with xmgrace

s0 line color "blue"
s0 linewidth 2.5
HARDCOPY DEVICE "PNG"
PAGE SIZE 800, 600
xaxis tick major grid on
yaxis tick major grid on
xaxis tick major color "grey"
yaxis tick major color "grey"

How could I use more colors on my graphs (e.g. to use HEX or other format instead of simple definition of the color ID) ?

Are there more ideas to improve general qualities of the produced PNG images?


Solution

  • The default xmgrace style sucks, but there is a way out:

    • Take an empty agr file and edit its style to suit your needs. This means changing the appearance of the axis, the size of the lines, etc.
    • Name it Default.agr and place it in the ~/.grace/templates/ folder (it might be necessary to create the folder beforehand)

    To add colours, open the Default.agr file and look for the @map color lines. Add any line you want (taking care not to have repeated colour indices), or change the existing ones. Colours should be specified with the RGB format and are always fully opaque.

    For instance, my default.agr file contains the following lines:

    @map color 0 to (255, 255, 255), "white"
    @map color 1 to (0, 0, 0), "black"
    @map color 2 to (227,26,28), "red"
    @map color 3 to (51,160,44), "green"
    @map color 4 to (31,100,180), "blue"
    @map color 5 to (255, 127, 0), "orange"
    @map color 6 to (106,61,154), "violet"
    @map color 7 to (177,89,40), "brown"
    @map color 8 to (220, 220, 220), "grey"
    @map color 9 to (251,154,153), "light red"
    @map color 10 to (178,223,138), "light green"
    @map color 11 to (166,206,227), "light blue"
    @map color 12 to (253,191,111), "light orange"
    @map color 13 to (202,178,214), "lilla"
    @map color 14 to (212,184,127), "light brown"
    @map color 15 to (139, 0, 0), "red4"
    @map color 16 to (0, 139, 0), "green4"
    @map color 17 to (0, 0, 139), "blue4"
    @map color 18 to (139, 139, 139), "grey4"
    

    which gives the following palette:

    palette

    Now you can use the new colour indexes (or the colour names) in your batch files. Note that you can add map color lines directly to your batch file, like this:

    s0 line color "blue"
    s0 linewidth 2.5
    map color 13 to (202,178,214), "lilla"
    HARDCOPY DEVICE "PNG"
    PAGE SIZE 800, 600
    xaxis tick major grid on
    yaxis tick major grid on
    xaxis tick major color "lilla"
    xaxis tick major color "grey"
    yaxis tick major color "grey"