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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.