如何绘制原始数据点的交集?

时间:2017-09-25 16:04:11

标签: python numpy matplotlib plot

所以我试图绘制我绘制的两条线的交点。事实是,这两行中的每一行是通过具有两个相同大小的列表并且仅排列值来绘制的。基本上是每条线的时间与价值。什么是最好的方法,我正在尝试我的解决方案,但它不起作用。我正在考虑尝试将原始数据放在函数的形式,但我不知道该怎么做,我不知道该怎么做。我正在使用python 2.7。

所以我使用这些模块/包:

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import numpy.ma as ma
import time
import bisect
import datetime
import matplotlib.dates as mdates
from spacepy import pycdf

以下是我的尝试:

 def intersection(time,time_3A,L1,L2):
 #looks for times within a certain threshold of each other, and cechks if their values are within a certain thershold of each other. 
 #returns a list of tuples that contain points of approximate intersections 
    points = []
    for t in range(0, len(time) - 1,30):
        for  s in range(0, len(time_3A) - 1, 30):
            if abs(time[t] - time_3A[s]).seconds < 300 : 
                # print "T1:" + str(time[t])
                # print "T2:" + str(time[s])
                if abs(L1[t] - L2[s]) < .5 :
                    point = (time[t],L1[t])
                    points.append(point)
    return points

我正在使用matplotlib绘制我的数据:ax = plt.subplot2grid((3,3),(0,0)) ax1 = plt.subplot2grid((3,3),(1,1))

1 个答案:

答案 0 :(得分:0)

时间只是另一个方面。我认为这应该通过做所有4D

来工作
tdif = abs(time[:, None] - time_3A).seconds    #2d array of time differences
tmask = tdif < 300                             #2d array of booleans
Ldif = abs(L1[:, None] - L2)                   #2d array of distance
Lmask = Ldif < .5                              #2d array of booleans

mask = np.any(np.logical_and(tmask, Lmask), axis = 1)
points = np.c_[time[mask], L1[mask]]
相关问题