Plotting multiple datasets with gnuplot

Discussion in 'Python' started by Rob Garrett, Oct 9, 2009.

  1. Rob Garrett

    Rob Garrett Guest

    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.
     
    Rob Garrett, Oct 9, 2009
    #1
    1. Advertisements

  2. 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.
     
    Gabriel Genellina, Oct 9, 2009
    #2
    1. Advertisements

  3. Rob Garrett

    Snorri H Guest

    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.
     
    Snorri H, Oct 12, 2009
    #3
  4. Rob Garrett

    s.c.wouters Guest

    I just spend an hour searching the web for a similar problem and finally found your answer. Thank you, it works great!
     
    s.c.wouters, May 12, 2014
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.