Plotting multiple datasets with gnuplot


R

Rob Garrett

Hi,
I'm trying to get gnuplot to display multiple data series on a single
plot using gnuplot in python. I've searched around and haven't found
a solution to how to do this when I have a variable-length list of
plots to add.

For example, the following code will work:

plotData1 = Gnuplot.PlotItems.Data(data1, title="title1")
plotData2 = Gnuplot.PlotItems.Data(data2, title="title2")
g.plot( plotData1, plotData2 )

[I've removed the rest of the code for clarity]

But how can I do the following instead:

data = []
....
# Populate data
....
plots = []
for dataSet in data:
plots.append(dataSet)
g.plot(plots)

I don't know how many plots I'll be wanting to plot, but the number
will be roughly 15-20 and it seems ridiculous to have to hand-write
individual setup for each plot when I should be able to just loop
through the datasets and add them to gnuplot automatically.

Any help would be much appreciated!

Thanks,
Rob

PS mulitplot isn't the solution - this places plots literally on top
of each other, it doesn't plot different sets of data on the same axes.
 
Ad

Advertisements

G

Gabriel Genellina

I'm trying to get gnuplot to display multiple data series on a single
plot using gnuplot in python. I've searched around and haven't found
a solution to how to do this when I have a variable-length list of
plots to add.

For example, the following code will work:

plotData1 = Gnuplot.PlotItems.Data(data1, title="title1")
plotData2 = Gnuplot.PlotItems.Data(data2, title="title2")
g.plot( plotData1, plotData2 )

[I've removed the rest of the code for clarity]

But how can I do the following instead:

data = []
...
# Populate data
...
plots = []
for dataSet in data:
plots.append(dataSet)
g.plot(plots)

g.plot(*plots) should work; it's like calling g.plot(plots[0], plots[1],
plots[2]...)

See http://docs.python.org/reference/expressions.html#calls for the gory
details.
 
S

Snorri H

Hi,
I'm trying to get gnuplot to display multiple data series on a single
plot using gnuplot in python. I've searched around and haven't found
a solution to how to do this when I have a variable-length list of
plots to add.

What module are you using for interfacing python to gnuplot? I was
using gnuplot.py (http://gnuplot-py.sourceforge.net) package and it
was pretty easy to plot variable number of datasets on a single plot
with or without multiplot (however more than seven datasets per plot
looks ugly imho). In this case all you have to do is to create a
proper string with commands and pass it to gnuplot.

S.H.
 
Ad

Advertisements

S

s.c.wouters

I'm trying to get gnuplot to display multiple data series on a single
plot using gnuplot in python. I've searched around and haven't found
a solution to how to do this when I have a variable-length list of
plots to add.

For example, the following code will work:

plotData1 = Gnuplot.PlotItems.Data(data1, title="title1")
plotData2 = Gnuplot.PlotItems.Data(data2, title="title2")
g.plot( plotData1, plotData2 )

[I've removed the rest of the code for clarity]

But how can I do the following instead:

data = []
...
# Populate data
...
plots = []
for dataSet in data:
plots.append(dataSet)
g.plot(plots)

g.plot(*plots) should work; it's like calling g.plot(plots[0], plots[1],
plots[2]...)

See http://docs.python.org/reference/expressions.html#calls for the gory
details.

I just spend an hour searching the web for a similar problem and finally found your answer. Thank you, it works great!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top