gnuplot多个文件并添加y值单个图 [英] gnuplot multiple files and adding y values single plot

查看:88
本文介绍了gnuplot多个文件并添加y值单个图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据集,希望在gnu图上仅用一条线绘制它们.

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

我希望该行代表两个数据集中y值的总和

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

这两个数据集分别具有x和y值.

The two data sets have x and y values.

我想将两个数据集中的两个y值相加.

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

数据集中的x点有时相同,有时不一样.

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

示例数据集为

数据集一

x    y
1    5
2    6
3    5
4    6

数据集二

x      y
1      1
1.7    2
3      3
7      5

推荐答案

在我看来,您打算比我通常在Gnuplot中感到满意的做更多的数学运算.您是否考虑过将工具作为python与pandas一起使用?

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?

这可能是一个学习曲线,但这可能是学习新工具的时候了. http://pandas.pydata.org/pandas-docs/dev/10min. html

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()

为您提供输出:

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

我没有立即弄清楚如何定义add应该检查x列,而不是添加时检查索引.我看了一下:添加两个熊猫数据框在Pandas DataFrame对象中定义索引

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

这篇关于gnuplot多个文件并添加y值单个图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆