Python samples
Here are some basic examples of Python scripts to pilot PrestoPlot.
Load data file, create a graph
In this example, we'll load a data file, create a graph and export it to a PNG image.
from pyprestoplot import PrestoPlot
# Start a non-visible PrestoPlot instance, using the embedded PrestoPlot version.
pp = PrestoPlot()
# Load a data file (adjust location)
pp.fileManager.loadDataFile("/some/data/file.csv")
# Create a graph and fetch its reference
graph = pp.graphManager.createGraph("Dataset1", "Dataset2")
# Make some graph customisation
graph.title = "My custom graph"
# Save this graph as an image (adjust location)
graph.saveAsImage("/some/image.png","1024x800")
pp.exit()
Load data from pyhton, create a graph
In this example, we'll load data we are handling in the python script, directly to PrestoPlot, without using a file. We then create a graph and export it to a PNG image.
import math
from pyprestoplot import PrestoPlot
# Start a non-visible PrestoPlot instance, using the embedded PrestoPlot version.
pp = PrestoPlot()
# Create a dataset we'll populate from python
dataset = pp.datasetManager.createDataset("MyDataset")
# Let's get some data arrays
x = []
y = []
for i in range(0,10000):
x.append(i)
y.append(math.cos(i / 100.0))
# Feed PrestoPlot dataset with this data
dataset.addPoints(x,y)
dataset.dateformat = pp.dateManager.FORMAT_SECONDS
# Create a graph and fetch its reference
graph = pp.graphManager.createGraph(dataset)
# Make some graph customisation
graph.title = "Data from Python"
# Save this graph as an image (adjust location)
graph.saveAsImage("/some/image.png","1400x800")
pp.exit()