AppleScripting and Python Scripting of PublishPlot
This section explains the basic scripting steps needed to create and edit plots. Once scripts are written, they can be installed in the "Scripts" menu to add new features to PublishPlot. The documentation topics for writing scripts are:
◊ Creating a Plot
◊ PublishPlot Scripting Objects and Attributes
- Application
- Plot Document
- Axis Titles
- Axis Scales
- Plot Frame
- Plotted Data Set
- Plot Text Annotation
- Plot Arrow (and other shapes)
◊ PublishPlot Scripting Commands
◊ Python Utilities
Note: Apps distributed through the AppStore currently are only allowed to run scripts written in AppleScript (and only Apple scripts are recognized in the "Scripts" menu). PublishPlot, however is capable of running python scripts. On the chance that Apple will someday re-instate python scripting of Apps, this help topic also describes changes needed to script using python instead of AppleScript. For current use, however, you should write only using AppleScript.
Creating a Plot
The following AppleScript creates a simple plot in PublishPlot and changes a few of its properties (see below for a python script that does the same thing).
-- create data for the plot
set myTable to "#setName f(x)" & return
repeat with i from 0 to 100
set x to i * 3 / 100
set fval to 1 + x * x * x / 3 - 3 * x * x / 2 + 2 * x
set myTable to myTable & x & " " & fval & return
end repeat
-- create the plot in PublishPlot
tell application "PublishPlot"
if number of documents is 0 then
make new document
else if (number of plots of front document) > 0 then
make new document
end if
tell front document
set dset to plot table data myTable
repeat while refreshed is false
end repeat
set object color of dset to "blue"
set label of x title to "x"
set label of y title to "f(x)"
set automatic of y scale to false
set ticks of y scale to {0.5, 2.5, 0.5, 0}
set tlab to add label annotation "x^3/3-3x^2/2+2x+1" position {0.6, 2.2}
set parw to add arrow tail and head {0.5, 2.1, 0.7, 1.8}
end tell
end tell
The first section creates a table of data in a text variable (myTable). The table must follow the standard PublishPlot table format (and can include more table commands at the start of the table).
The second section creates the plot in PublishPlot. The script starts by creating a new document (unless the front document is empty with no plots). Next the plot table command is used to create a plotted data set. The subsequent loop waits until the plot is drawn before proceeding (such loops are sometimes needed). This plot table command returns a reference to the new data set, which is used to change the color of the plotted line. The next few commands set various features of the plot document (such as labels for x and y axes and settings for the tick marks along the y axis). Finally, the last two lines in the tell front document section use two scripting commands to add plot annotation text and a plot arrow.
This script has the basic structure for all scripts to create plots using PublishPlot. You can read about the various plot objects and their attributes for the numerous ways the plot can be customized under script control. For example, another common use for scripts is to do calculations on current plots. The script then reads the data from plots and runs calculations. For example, a script could find area under a curve by numerical integration.
The Same Sample Script in python
The following python script creates a simple plot in PublishPlot and changes a few of its properties.
from Foundation import *
from ScriptingBridge import *
pplot = SBApplication.applicationWithBundleIdentifier_("com.geditcom.PublishPlot")
pplot.activate()
# create data for the plot
sdata = []
sdata.append("#setName f(x)")
for i in range(100):
x = i*3./100.
f = 1 + x*x*x/3.-3.*x*x/2.+2*x
sdata.append(str(x)+","+str(f))
stext = '\n'.join(sdata)
# find plot document
if pplot.documents().count()==0 :
pdoc=pplot.classForScriptingClass_("document").alloc().init()
pplot.documents().addObject_(pdoc)
else :
pdoc = pplot.documents()[0]
if pdoc.plots().count()>0 :
pdoc=pplot.classForScriptingClass_("document").alloc().init()
pplot.documents().addObject_(pdoc)
# create the plot in PublishPlot
dset = pdoc.plotTableData_(stext)
dset.setObjectColor_("blue")
pdoc.xTitle().setLabel_("x")
pdoc.yTitle().setLabel_("f(x)")
pdoc.yScale().setAutomatic_(False)
pdoc.yScale().setTicks_([0.5, 2.5, 0.5, 0])
pdoc.addLabelAnnotation_position_("x^3/3-3x^2/2+2x+1",[0.6,2.2])
pdoc.addArrowTailAndHead_([0.5, 2.1, 0.7, 1.8])
The first two "from" lines import modules needed by python scripts. These imports allow python scripts to control any Mac application that can be scripted by Applescript (albeit not those that follow extra restrictions imposed on AppStore apps known as "sandboxing"). The third line uses a standard scripting bridge method to fetch a reference to the PublishPlot application (stored in pplot). All python scripts for PublishPlot should begin with these initial lines.
The next section creates a table of data in a list variable (sdata); the list lines are joined in the text variable stext. The table must follow the standard PublishPlot table format (and can include more table commands at the start of the table).
The find plot document section opens the front document, creating a new document if none found or if the front document is not empty.
The last section uses a plot table command to create the plot. This command returns a reference to the new plotted data set, which is used in the next line to change the color of the plotted line. The next few commands set various features of the plot document (such as labels for x and y axes and settings for the tick marks along the y axis). Finally, the last two lines use two scripting commands to add plot annotation text and a plot arrow.
This script has the basic structure for all python scripts to create plots using PublishPlot. You can read about the various plot objects and their attributes for the numerous ways the plot can be customized under script control. Other python scripts might read data in current plots and make some calculations.
PublishPlot Scripting Objects and Attributes
This section describes all the scriptable objects in PublishPlot. You can use attributes of various objects to customize the appearance of the plot. Some objects respond to commands for additional options. You can also open the PublishPlot dictionary using Apple's Script Editor. That dictionary defines the entire scripting suite, but in less detail than provided here. The dictionary also assumes you are using Apple Script, while this documentation covers changes needed for python use as well.
You can set or get attributes in Apple Script using:
set object color of plot 2 to "red" set lw to line width of plot 1
You can set or get attributes in python using:
dset = pdoc.plots()[0]
dset.setObjectColor_("red")
lw = dset.lineWidth()
Here pdoc is a document object. Attributes in Apple Script many be one or more words. If the attribute is a single word, it has the same name in python but is followed by parentheses (e.g., frame becomes frame()). If it has multiple words, the spaces are removed and the first letter of the second word on are capitalized (e.g., object color becomes objectColor()). To set an attribute in python, begin with set, capitalize the first letter of python attribute name, and append an underscore (e.g., to set object color use setObjectColor_("red")). A common error when using python is to omit the underscore character in set commands; it is required.
- PublishPlot Application
- The application object contains documents (e.g.,
front document,document 1, etc.). In python,pplot.documents()is an ordered list of documents (e.g.,pplot.documents()[0]is the front document). - Plot Document
- Each window in PublishPlot is a plot document. Each document contains:
plots- plotted data sets (plots()in python). Normally you create plots with the plot table command. You can delete a plotted data set withdelete plot 2(orpplot.plots()[1].delete()in python).text labels- plot text annotation (textLabels()in python). Normally you add text annotation with the add label command. You can delete a text label withdelete text label 1(orpplot.textLabels()[0].delete()in python).plot arrows- arrows on the plot (plotArrows()in python). Normally you add arrows with the add arrow command. You can delete an arrow withdelete text label 1(orpplot.plotArrows()[0].delete()in python).
x title(xTitle()in python) - an axis title object for the x axis title.y title(yTitle()in python) - an axis title object for the y axis title.x scale(xScale()in python) - an axis scale object for the x axis scale (e.g., tick mark locations and labels).y scale(yScale()in python) - an axis scale object for the y axis scale (e.g., tick mark locations and labels).frame- a frame object for frame or axes in the plot document.selected plot(selectedPlot()in python) - The currently selected plot data set. If no plot is selected, it returns the front-most plot in the document. If the document has no plots, it returns an empty string ("").bar chart(barChart()in python)- true if the document is a bar chart document or false if it is a numeric or an empty document.refreshed- some scripting actions (as indicated below) set this property to false and it remains false until internal code has redrawn the plot. See plot table command for when this attribute is needed.plot size(plotSize()in python) - the size of the content area for the plot window in a list with {width, height}. The dimensions are in pixels.
plot size. - Axis Title
- This object controls the content and style for main label or title for each axis. It has the following attributes:
label- the text of the title.font name(fontName()in python) - the name of the font to use for the title.font size(fontSize()in python) - the size of the font in points. The entered points would be the actual font size for a full-page landscape mode plot. The font size will scale proportionally to other size plots.object color(objectColor()in python) - the color for the title [1].
- Axis Scale
- This object controls the tick mark locations along the axis as well as the font used to label the tick marks. It has the following attributes:
automatic- true or false to automatically calculate plot limits and tick mark spacings from the plotted data (setsrefreshedto false if changed).ticks- the tick mark settings as an array of four numbers: [minimum value, maximum value, tick mark spacing, number of minor tick marks between major tick marks]. Note that setting the ticks (usingsetTicks_()in python) will not take effect unlessautomaticis first set to false.include zero(includeZero()in python) - true or false to determine if zero should be between the minimum and maximum for the axis (setsrefreshedto false if changed).frame inside(frameInside()in python) - true or false to draw tick marks on the inside of framed plots.frame outside(frameOutside()in python) - true or false to draw tick marks on the outside of framed plots.axes inside(axesInside()in python) - true or false to draw tick marks on the inside of plots using axes.axes outside(axesOutside()in python) - true or false to draw tick marks on the outside of plots using axes.log axis(logAxis()in python) - true or false for the axis to be a log axis (setsrefreshedto false if changed).font name(fontName()in python) - the name of the font to use for the tick labels.font size(fontSize()in python) - the size of the font in points. The entered points would be the actual font size for a full-page landscape mode plot. The font size will scale proportionally to other size plots.object color(objectColor()in python) - the color for the tick mark labels.
- Plot Frame
- This object controls the box or axes drawn with the plot and also controls the background color. It has the following attributes:
line width(lineWidth()in python) - width of lines, as percent of plot diagonal, for the plot frame or plot axes.tick length(tickLength()in python) - the tick mark length, as percentage of the plot diagonal.object color(objectColor()in python) - the color for lines for the plot frame or plot axes [1].box border(boxBorder()in python) - true to draw a frame around the plot or false to draw axes through an origin.origin- the origin when drawing plot axes as a list of two floating point numbers.labels on axes(labelsOnAxes()in python) - true to place labels next to axes (when axes are drawn) or false to be outside the plot area.major grid(majorGrid()in python) - true to draw grid at major tick marks.minor grid(minorGrid()in python) - true to draw grid at minor tick marks.pattern spacing(patternSpacing()in python) - spacing between lines when symbols filled with a pattern, as percent of plot diagonal.background color(backgroundColor()in python) - background color for the entire plot [1].opacity(opacity()in python) - set background color opacity from 1 for opaque to 0 for transparent.edge color(edgeColor()in python) - separate color to use for background of area outside the plot area [1].edge opacity(edgeOpacity()in python) - set edge color opacity from 1 for opaque to 0 for transparent.use edge color(useEdgeColor()in python) - the edge color is not used unless you set this attribute to true.
- Plotted Data Set
- This object controls the style for a single plotted data set in a plot. It has the following attributes:
name- any text string to name the plot; it appears in the inspector window when the data set is selected.plot data(plotData()in python) - list of two lists; the first is the x data and the second is the y data. For bar charts, the x data are text labels. Setsrefreshedto false.sorted data(plotData()in python) - list of all data points {{x1,y1},{x2,y2},{x3,y3},...{xn,yn}} sorted in increasing order by x value (read only). For bar charts, the x data are text labels and are sorted alphabetically.x errors(xErrors()in python) - list of 0, 1, or 2 lists for error bars in x direction; 0 means no error bars, 1 means + and - errors in single list, 2 has + errors in first list and - errors in second list. Setsrefreshedto false.y errors(yErrors()in python) - list of 0, 1, or 2 lists for error bars in y direction; 0 means no error bars, 1 means + and - errors in single list, 2 has + errors in first list and - errors in second list. Setsrefreshedto false.line width(lineWidth()in python) - width of line, as percent of plot diagonal, for the plotted data.object color(objectColor()in python) - the color for the plotted line [1].line type(lineType()in python) - the type of line drawn connecting the points. In Apple Script, choose from the defined constants below, but in python, those constants are not available and you have to translate the underlying 4-letter AppleEvent code usingsetLineType_(getCode(arg))whereargis the code. The constants (with codes in parentheses) are:
solid('Sold') - draw a solid line
dotted('Dotd') - draw a dotted line
dashed('Dash') - draw a dashed line
dashdotted('Dadt') - draw a dash-dot line
filled('Fill') - fill curve with line color
none('None') - do not connect the points with any line
ThegetCode()subroutine needed for python can be copied from below and pasted into your script.symbol line width(symbolLineWidth()in python) - width of lines drawn as the border of symbols, as percent of plot diagonal, at the plotted data points.symbol size(symbolSize()in python) - the size of symbols, as percent of plot diagonal, at the plotted data points.symbol line color(symbolLineColor()in python) - the color for lines drawn as the border of the symbols at plotted data points [1].symbol fill color(symbolFillColor()in python) - the color used to fill the symbols at plotted data points [1].opacity(opacity()in python) - set symbol fill color opacity from 1 for opaque to 0 for transparent.pattern type(patternType()in python) - use 0 for solid color file or 1 to 6 to fill symbols with one of the options in the pattern menu.symbol type(symbolType()in python) - the type of symbol drawn at data points. In Apple Script, choose from the defined constants below, but in python, those constants are not available and you have to translate the underlying 4-letter AppleEvent code usingsetSymbolType_(getCode(arg))whereargis the code. The constants (with codes in parentheses) are:
no symbol('symA') - do not draw symbols at data points
square('symB')
circle('symC')
diamond('symD')
triangle('symE') - triangle pointing up
inverted triangle('symF') - triangle pointing down
right triangle('symG') - triangle pointing to the right
left triangle('symH') - triangle pointing to the left
vertical bar('symI') - box from bottom of plot to the point, with width given by the symbol size
horizontal bar('symJ') - box from left of plot to the point, with width given by the symbol size
plus('symK') - plus sign
star('symL') - star or an asterisk symbol
ThegetCode()subroutine needed for python can be copied from below and pasted into your script.error bar type(errorBarType()in python) - set type of error bar to display by integer code: 1 for error columns, 2 to find standard deviations, 3 for box & whisker plots, 4 for box & whisker plots with outliers, 5 for violin plots, and 6 for violin plots with outliers. Enter a negative value to select a style, but to hide the error bar feature.error line width(errorLineWidth()in python) - width of lines used for error bars and other statistics graphics, as percent of plot diagonal.error size(errorSize()in python) - the size of end caps on error bars and half the width of boxes or probability densities in box & whisker or violin plots, as percent of plot diagonal.error line color(errorLineColor()in python) - the color for lines of error bars and other statistics graphics [1].stats tolerance(statsTolerance()in python) - width of x data blocks when finding standard deviations or evaluating box & whisker or violin plot features.box fill color(boxFillColor()in python) - the color used to fill boxes and probability densities in box & whisker or violin plots [1].box opacity(boxOpacity()in python) - set box fill color opacity from 1 for opaque to 0 for transparent.
- Plot Text Annotation
- This object controls the content and style for text annotation labels added to plots. It has the following attributes:
position- the location of the center of the label in the current plot coordinates. It is a list of two floating point numbers. Setsrefreshedto false.text size(textSize()) - return list with {width,height} for size of the label using units for the current plot (read only).- This object also inherits all attributes from axis title objects.
- Plot Arrow
- This object controls the style of all shapes including arrows, rectangles, ovals, lines, and a plot key used for plot annotation (the name is to be consistent with earlier versions that only had arrows). It has the following attributes:
shape type(shapeType()) - the type of shape to draw selected by integer code as: arrow (0), double arrow (1), rectangle (2), oval (3), line (4), plot key (5).tail and head(tailAndHead()in python) - the coordinates for the tail and head of the arrow or line or the corners of rectangles, ovals, and plot keys in a list of four floating point numbers - {x tail, y tail, x head, y head}. Setsrefreshedto falseline width(lineWidth()in python) - width of arrow line, as percent of plot diagonal.object color(objectColor()in python) - the color for arrow lines (but not the arrowhead), simple lines, and color of text used in plot keys [1].symbol size(symbolSize()in python) - the size of the arrow head, as percent of plot diagonals.symbol line color(symbolLineColor()in python) - the color for line drawn around the border of the arrow head or around the border of rectangles, ovals, and plot keys [1].symbol fill color(symbolFillColor()in python) - the color used to fill the arrow head or to fill rectangles, ovals, and plot keys [1].opacity(opacity()in python) - set opacity for the fill color for arrowheads, rectangles, ovals, and plot keys from 1 for opaque to 0 for transparent.font name(fontName()in python) - the name of the font used for plot keys (no effect on other shapes).
Notes
- Colors can be set by name (black, blue, brown, cyan, darkGray, gray, green, darkGreen, lightGray, magenta, maroon, orange, purple, red, white, or yellow) or by string with red, green, and blue values between 0 and 1 (entered as "(red green blue)" and values can be separated by spaces, tabs, or commas).
PublishPlot Scripting Commands
The following scripting commands perform extra functions. Each command gives the AppleScript form and the python form. In AppleScript the order of arguments does not matter and some are optional (indicated with [square brackets]). In python, the order is specified by the function name and all must be provided (although you can pass None for optional arguments that are not needed).
Unless otherwise noted, all these commands can be sent to plot documents. The user input commands (get option and get input) can be sent to the application in AppleScript, but only work when sent to a document in python.
plot table data myTable(Apple Script)
plotTableData_(myTable)(python)- This command plots the table of data in the document that is the target of the command. The
myTableargument is a text argument with table data formatted as expected for PublishPlot tables. Note that this command may return before the table is actually plotted in code. As a consequence, reading or setting features of the new plot that depend on range of the data may not work correctly. The solution, when needed, is to delay the script until the new data are done plotting. A script snipped to this task istell front document set dset to plot table data myTable repeat while refreshed is false end repeat end tellThe command set refreshed (which is plot document attribute) to false and it will only return to true after the plot has been drawn. The repeat loop continues until it returns to true. Like theplot tablecommand any other command or attribute that might change the range will also setrefreshedto false (as indicated). If needed, these commands can be following be a similar loop, but the need for such loops is uncommon. plot expression function "x^2" xMin 0 xMax 10 [points 100](Apple Script)
plotExpressionFunction_xMax_xMin_points_("x^2",10,0,100)(python)- This command plots the expression in the
functionargument fromxMintoxMaxusing the optional number ofpoints(default is 100). The expression is plotted in the document that is the target of the command. Setsrefreshedto false. add label annotation "Hello" position {20,30}(Apple Script)
addLabelAnnotation_position_("Hello",[20,30])(python)- Add a text annotation label in the target document with text given by the annotation argument and located at the position argument. The position specifies the center of the label. Sets
refreshedto false. add arrow tail and head {20,30,50,90}(Apple Script)
addArrowTailAndHead_([20,30,50,90])(python)- Add an arrow annotation to the target document. The arrow starts at the tail position and points to the head position. Those coordinates are specified in a list of four numbers — {tail x, tail y, head x, head y}. Sets
refreshedto false. add double arrow tail and head {20,30,50,90}(Apple Script)
addDoubleArrowTailAndHead_([20,30,50,90])(python)- Add an double arrow annotation to the target document. The two arrowheads are at the tail and head positions. Those coordinates are specified in a list of four numbers — {tail x, tail y, head x, head y}. Sets
refreshedto false. add rectangle tail and head {20,30,50,90}(Apple Script)
addRectangleTailAndHead_([20,30,50,90])(python)- Add a rectangle shape to the target document. Two opposite corners of the rectangle are at the tail and head positions. Those coordinates are specified in a list of four numbers — {tail x, tail y, head x, head y}. Sets
refreshedto false. add plot key tail and head {20,30,50,90}(Apple Script)
addPlotKeyTailAndHead_([20,30,50,90])(python)- Add a plot key to the target document. Two opposite corners of the plot key's rectangle are at the tail and head positions. Those coordinates are specified in a list of four numbers — {tail x, tail y, head x, head y}. Sets
refreshedto false. To change font and color used for the key use the following:set pk to add plot key tail and head {20,30,50,90} set font name of pk to "Times" set object color of pk to "red" add oval tail and head {20,30,50,90}(Apple Script)
addOvalTailAndHead_([20,30,50,90])(python)- Add an oval shape to the target document. Two opposite corners of the rectangle that circumscribes the oval are at the tail and head positions. Those coordinates are specified in a list of four numbers — {tail x, tail y, head x, head y}. Sets
refreshedto false. add line tail and head {20,30,50,90}(Apple Script)
addLineTailAndHead_([20,30,50,90])(python)- Add a line shape to the target document. The line is drawn between the tail and head positions. Those coordinates are specified in a list of four numbers — {tail x, tail y, head x, head y}. Sets
refreshedto false. get limits after x1 before x2(Apple Script)
getLimitsAfter_before_(x1,x2)(python)- This command can only be sent to a plotted data set and it returns {xmean, xmin, xmax, ymean, ymin, ymax} for the data in a list with 6 items. The optional after and before arguments can get limits only for data points with x after x1 and before x2. If only one optional parameter is used the limits are for data after x1 or before x2 (whichever is specified).
export pdf toPath filePath(Apple Script)
exportPdfToPath_(filePath)(python)- Exports the target document to a pdf file. The
filePathargument specifies a full path to the new file with folders delimited by slashes ("/"). Due to Apple restrictions on AppStore apps, the path must be to a file in your "Pictures" folder. If the file is in a subfolder in the "Pictures" folder, that subfolder must already exist. This command returns true if the file is saved or false if the path is either invalid or to a locations that does not allow saved files. get option [title "Main Text"] [message "Sub Text"] [buttons {"Yes","No"}](Apple Script)
getOptionButtons_message_title_(["Yes","No"],"Sub Text","Main Text")(python)- Will display a dialog box to the user with one to three buttons (provided in the list). The title is in bold and main text of the window. The message appears below the title to provide extra information. The first button is the default button and the buttons appear right to left. The returned result of this command is the text of the clicked button.
This command can be done with the display dialog command in Apple Script. It is provided in PublishPlot for use in python scripts or as an alternative in AppleScripts. get input [title "Title"] [prompt "Prompt"] [buttons {"OK","Cancel"}] [initial text "0"](Apple Script)
getInputButtons_initialText_prompt_title_(["OK","Cancel"],"0","Prompt","Title")(python)- Will display a dialog box where the user can enter one line of text. The required
promptis displayed above the text field to explain the requested input (it can be any length and use multiple lines). The optionalinitial textis placed in the text field (it can only be a single line). The optionaltitleis displayed in the title bar of the window. The optionalbuttonscan change the text of the default "OK" and "Cancel" buttons and optionally add a third button. The returned result of this command is a list with two items. The first item is the text of the button that was clicked. The second item is the text entered by the user in the text field.
This command can be done with the display dialog command in Apple Script. It is provided in PublishPlot for use in python scripts or as an alternative in AppleScripts. get file [start "/Users/home/Desktop"] [extensions {"pplot"}] [title "Open"] [prompt "Pick a plot file"](Apple Script)
getFileExtensions_prompt_start_title_(["pplot"],"Pick a plot file","/Users/home/Desktop","Open")(python)- Will display standard MacOS panel for user to select an existing file. The
startparameter can be used to define the initially selected folder and/or file. Theextensionslist means the user can only select files with those extensions. Thetitleis title for the open panel window. Thepromptis a string that will appear in the window. When done, the command will return the full path to the selected file (or empty if canceled). Thestartfile path and returned file path delimit folders with slashes ("/")
This command can be done with the choose file command in Apple Script. It is provided in PublishPlot for use in python or as an alternative in AppleScripts. put file [start "/Users/home/Desktop"] [extensions {"pdf"}] [title "Save"] [prompt "Export PDF to this location"](Apple Script)
putFileExtensions_prompt_start_title(["pdf"],"Export PDF to this location","/Users/home/Desktop","Save")(python)- Will display standard MacOS panel for selecting file name and location for saving a file. The
startparameter can be used to define the initially selected folder and/or file name (the file need not exist and you can supply just the name if the start folder is not important). Theextensionslist means the user should save to files with those extensions; if they choose another extension, they will be prompted to use the first extension in the list. Thetitleparameter is the title for the save panel. Thepromptis a string that will appear in the window. If the selected file already exists, the user will be asked to confirm that it is OK to replace that file. When done, the command will return the full path to the selected file delimited by slashes ("/") or empty if the process is canceled.
This command can be done with the choose file name command in Apple Script. It is provided in PublishPlot for use in python scripts or as an alternative in Apple Scripts.
Python Utilities
Because python cannot make use of constants defined in the Apple Scripting dictionary for PublishPlot, you have you use the underlying integer constant. This constant is calculated from a 4-letter Apple event code by interpreting the 4 ASCII bytes as a 8 byte integer. A simple subrouting to input a 4-letter code and return the integer version is given below. You can copy and paste to your python script if you need to make use of PublishPlot constants.
# input four code string and return integer value
# of its hexadecimal representation (returns 0 if not 4 letters)
def getCode(enumCode) :
code = map(ord,enumCode)
if len(code)!=4 : return 0
return code[3]+256*(code[2]+256*(code[1]+256*code[0]))