0

I am trying to plot some data in an automated way. To this end, I perform some pre-processing in Bash and then intend to generate a plot command to be fed into Gnuplot in order to actually plot my data.

Beyond just plotting the data itself, I also want to create fitting lines for my data sets. Schematically my approach looks like this:

Some preprocessing

for every dataset
  fit f(x) = m * x + c

  plot f(x)
  plot actual data points

I am using the pdfcairo terminal in order to produce a PDF as the output file. In principle everything is working as intended, except that every plot command creates a new page in the output PDF that then contains only the graph corresponding to this single plot command.

However, what I want is to combine all these individual graphs into a single diagram. Essentially, I am looking for a way to have the separate plot commands act as if I had used a single plot command to plot all data sets at once, as in

plot sin(x), cos(x), exp(x)

However, I (think I) can't combine my plot commands in this way as I have the fits in between and these always overwrite the previous result variables.

While searching the web, I stumbled upon this answer which suggests using the replot command instead of the regular plot command. However, this will still produce a new page for every replot invocation, however this way each consecutive diagram will at least contain the data from the previous plots (which is what I want). This command also has the problem that it only works after an inital plot has been issued, which doesn't lend itself (conveniently) to a processing in a loop as I am trying to do.

Is there an argument to plot or a setting that I can specify that causes each plot command to just add a graph to the same diagram, so that I end up with a single page containing a single diagram showing multiple graphs for my different data sets?

As a very simple MWE, let's consider

# Apply magic flag
plot sin(x) title "A"
plot cos(x) title "B"

which I want to produce the same output as if I had used

plot sin(x) title "A", cos(x) title "B"

EDIT: Actually the replot approach has another significant drawback: With that, only the fit line for the last fitted data set will be plotted as apparently the data is created at the very end at which point all fit lines are using the same variables (which get overwritten every time we do a fit)

Raven
  • 2,563
  • 1
  • 20
  • 34

0 Answers0