Automatically Creating a Graph

With the collective ability to automatically draw lines and text boxes, Scribus can, without a great deal of work, be used to automatically generate a graph structure. Here I will show some basic Python commands to do that. This early version will give three requestors, the first for a title of the graph, the second and third for the labels of the X-axis and Y-axis respectively. The dimensions and coordinates used are presuming points as page units.

Script: graph.py

 * 1) !/usr/bin/env python


 * 1) File: graph.py
 * 2) originally 2006.05.17
 * 3) creates basic graph with axis labels

import scribus

xorigin = 150     # x-origin of graph yorigin = 450    # y-origin of graph xaxis=400     #x axis length yaxis=350     #y axis length color="Black" a = 1.5 # width of lines if scribus.haveDoc: title = scribus.valueDialog('Title','Enter Title') xlabel = scribus.valueDialog('X-axis Label','Enter X-Label') ylabel = scribus.valueDialog('Y-axis Label','Enter Y-Label') scribus.setRedraw(1) scribus.setUnit(0) d = scribus.createLine(xorigin,yorigin,xorigin+xaxis,yorigin) scribus.setLineWidth(a, d)   scribus.setLineColor(color, d)    scribus.setFillColor(color, d)    e = scribus.createLine(xorigin,yorigin,xorigin,yorigin-yaxis) scribus.setLineWidth(a, e)   scribus.setLineColor(color, e)    scribus.setFillColor(color, e)    T = scribus.createText(60, 45, 500, 60) scribus.setTextColor("Red", T)   scribus.setText(title, T)    scribus.setTextAlignment(1, T)    scribus.setFont("Nimbus Roman No9 L Bold", T)    scribus.setFontSize(28, T)    XL = scribus.createText(xorigin, yorigin + 20, xaxis, 40) scribus.setText(xlabel, XL) scribus.setTextAlignment(1, XL) scribus.setFont("Luxi Sans Regular", XL) scribus.setFontSize(20, XL) YL = scribus.createText(xorigin - 60, yorigin, yaxis, 40) scribus.setText(ylabel, YL) scribus.setTextAlignment(1, YL) scribus.setFont("Luxi Sans Regular", YL) scribus.setFontSize(20, YL) scribus.rotateObject(90,YL)
 * 1) Three requestors to get label names
 * 1) First draw the X-axis
 * 1) Now the Y-axis
 * 1) Comment out the above line, uncomment the next line for v1.3.3.x
 * 2)    e = scribus.createLine(xorigin,yorigin,xorigin+yaxis,yorigin)
 * 1) Uncomment the next line for v1.3.3.x
 * 2)    scribus.rotateObject(90,e)
 * 3) The Title text frame
 * 1) in Windows, substitute the font: "Times New Roman Bold" will work
 * 1) Label for X-axis
 * 1) For Windows, need a suitable font.
 * 1) Label for Y-axis, rotated
 * 1) For Windows, need a suitable font.

scribus.redrawAll