代码之家  ›  专栏  ›  技术社区  ›  youpilat13 Ty Petrice

绘制具有周期边界和无分段的NICES曲线

  •  4
  • youpilat13 Ty Petrice  · 技术社区  · 6 年前

    使用库 pyephem 我想找一种方法来绘制一个很好的曲线图(经度、纬度),它代表一颗卫星的地面轨迹。我已经计算了(经度,纬度),但是当经度超过+180度时,计算出的下一个值是-178度,这样就画出了一个段:这是个坏数字。

    下面是我现在得到的代码和数字。

    currentDate = date.datetime(2018,12,1,0,0,0);
    
    for i in range(nPoints):
      iss.compute(currentDate)
      # compute latitude
      posLat[i] = iss.sublat*(180/math.pi)
      # compute longitude
      posLong[i] = iss.sublong*(180/math.pi)
      currentDate = currentDate + date.timedelta(seconds = (time3orbits/nPoints*3600))                
      print currentDate, posLong[i], posLat[i]
    
    plt.plot(posLong,posLat)
    plt.show()
    

    这里是我得到的数字(对于绕地球运行的3个轨道): enter image description here

    如何防止绘制线段?当做

    iss.sublat iss.sublong 代表ISS位置的当前纬度和经度(从 currentDate 固定的)。

    1 回复  |  直到 6 年前
        1
  •  0
  •   a_guest    6 年前

    您可以将符号更改时的数据数组从正数拆分为负数,然后绘制单个子数组:

    orbits = np.argwhere(
        (data[:-1, 0] * data[1:, 0] < 0)
        & (data[1:, 0] < 0)
    ).ravel() + 1
    
    for orbit in np.split(data, orbits, axis=0):
        plt.plot(orbit[:, 0], orbit[:, 1])
    

    enter image description here