Search code examples
pythonpython-2.7xmgrace

Text boxes in xmgrace (preferably with GracePlot.py)


I am currently plotting figures with xmgrace from python using GracePlot.py and I would like to make text annotations in the graph and place them inside a box, in order to make the reading easy when the grid is on.

Does anybody know how to do it with GracePlot.py? Or from xmgrace GUI?

The code I use is similar to the following:

import GracePlot as xg
import math
from numpy import arange
x=arange(0,10,0.1)
y=[math.exp(-q) for q in x]
grace=xg.GracePlot()
graph=grace[0]
data=xg.Data(x=x,y=y)
graph.plot(data)
graph.text('This should be placed inside a box',5,0.5)

Solution

  • I had a quick look through the latest GracePlot module source code. It seems that the author has not yet implemented the capability to make boxes.

    Normally, the "Box" tool can be found under "Drawing Objects" when using the Grace/xmgrace GUI. Create a box and save the project, then view it in a text editor as the file is saved in an ASCII format. The following section can be found:

    @with box
    @    box on
    @    box loctype view
    @    box 0.340196078431, 0.691176470588, 0.619607843137, 0.513725490196
    @    box linestyle 1
    @    box linewidth 1.0
    @    box color 1
    @    box fill color 1
    @    box fill pattern 0
    @box def
    

    As you can see by comparing similar chunks for text creation etc. with the source code, the GracePlot module is just printing similar commands for each of the things it is generating. It would be quite easy to add the capability to make boxes. Perhaps you have time yourself? :)

    The capability for text has been implemented:

    from GracePlot import *
    p = GracePlot()
    [....]
    p.text('Hello, world!', 0.5, 0.4, color=violet, charsize=1.2)
    

    will place some violet-colored text at (0.5, 0.4) with 1.2 character size.

    Boxes in Grace do not have their own text, so in order to solve your question you can simply place a text object over the box you created.