1

I have two data sets and wish to plot them with just one line on a gnu plot graph.

I want the line to represent the sum of the y values in both data sets

The two data sets have x and y values.

I would like to add up the two y values from both data sets.

The x points in the data sets are some times the same and sometimes not.

example data sets are

data set one

x    y
1    5
2    6
3    5
4    6

data set two

x      y
1      1
1.7    2
3      3
7      5
Christoph
  • 47,569
  • 8
  • 87
  • 187
Jon
  • 171
  • 3
  • 12

2 Answers2

2

To me it sounds like you are planning on doing a bit more math than what I normally find comfortable doing in Gnuplot. Have you considered using a tool as python with pandas?

It can be a bit of a learning curve, but this might be the time to learn a new tool.. http://pandas.pydata.org/pandas-docs/dev/10min.html

This gets you pretty close to what you want I think.

import pandas as pd
import matplotlib.pyplot as plt

dataSet1 = pd.DataFrame( [ [1, 2], [2, 6], [3, 5], [4, 6] ], columns=list('xy'))
dataSet2 = pd.DataFrame( [ [1, 1], [1.7, 2], [3, 3], [7, 5] ], columns=list('xy'))

dataSet1 = dataSet1.set_index('x')
dataSet2 = dataSet2.set_index('x')

full_dataset =  dataSet1.add(dataSet2, fill_value=0)
print full_dataset

full_dataset.plot()
plt.show()

Gives you the output:

     y
x     
1.0  3
1.7  2
2.0  6
3.0  8
4.0  6
7.0  5

Output Plot

I didn't immediatly figure out how to define that add should check the x column, not the index when adding. I looked a bit at: Adding two pandas dataframes and Redefining the Index in a Pandas DataFrame object

Community
  • 1
  • 1
Trygve
  • 493
  • 3
  • 15
1

Assuming that you can use cat, you can first concatenate the two files with cat fileA.txt fileB.txt and the plot with the option smooth frequency which adds all y-values for the same x-values:

plot '< cat fileA.txt fileB.txt' smooth frequency with lines
Christoph
  • 47,569
  • 8
  • 87
  • 187