【问题标题】:Geographical data plot/map with lines in python and matplotlib在 python 和 matplotlib 中带有线条的地理数据图/地图
【发布时间】:2015-11-03 11:44:03
【问题描述】:

我记得在一篇博客文章中看到了一种可视化地理数据的好方法。它只是代表纬度的线和要显示的变量的线的高点。我试着在下面的图片上画出它:

你们中的一些人还记得图书馆甚至是解释如何生成这些地图的博客文章吗? (我依稀记得是matplotlib & python,但我很可能是错的)

【问题讨论】:

    标签: python matplotlib plot geospatial geo


    【解决方案1】:

    我认为这是您想要的 - 在 3d 轴上绘制恒定纬度线。我已经解释了每个部分在 cmets 中的作用

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    import numpy as np
    import itertools
    
    #read in data from csv organised in columns labelled 'lat','lon','elevation'
    data = np.recfromcsv('elevation-sample.csv', delimiter=',')
    
    # create a 3d axis on a figure
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    
    # Find unique (i.e. constant) latitude points
    id_list = np.unique(data['lat'])
    
    # stride is how many lines to miss.  set to 1 to get every line
    # higher to miss more
    stride = 5
    
    # Extract each line from the dataset and plot it on the axes
    for id in id_list[::stride]:
        this_line_data = data[np.where(data['lat'] == id)]
        lat,lon,ele = zip(*this_line_data)
        ax.plot(lon,lat,ele, color='black')
    
    # set the viewpoint so we're looking straight at the longitude (x) axis
    ax.view_init(elev=45., azim=90)
    
    ax.set_xlabel('Longitude')
    ax.set_ylabel('Latitude')
    ax.set_zlabel('Elevation')
    ax.set_zlim([0,1500])
    
    plt.show()
    

    我用来测试的数据集不是我的,而是在github here上找到的。

    这给出如下输出:

    注意 - 如果我误解了您草图中的轴标签,您可以交换纬度和经度。

    【讨论】:

    • 正是(!)我在找什么 :)
    • 太棒了!我记得在一件 T 恤上看到过这样的东西——不过现在找不到了 :)
    • 我也看到了,我认为这是地球的地形图。但我也找不到。
    【解决方案2】:

    您是否正在考虑类似于this 的 3D 情节?可能你也可以做一个像this这样的级联图?最后一种情节的代码是这样的:

    # Input parameters:
    padding = 1    # Relative distance between plots
    ax = gca()     # Matplotlib axes to plot in
    spectra = np.random.rand((10, 100))   # Series of Y-data
    x_data = np.arange(len(spectra[0]))   # X-data
    
    # Figure out distance between plots:
    max_value = 0
    for spectrum in spectra:
        spectrum_yrange = (np.nanmax(spectrum) -
                           np.nanmin(spectrum))
        if spectrum_yrange > max_value:
            max_value = spectrum_yrange
    # Plot the individual lines
    for i, spectrum in enumerate(spectra):
        # Normalize the data to max_value
        data = (spectrum - spectrum.min()) / float(max_value)
        # Offset the individual lines
        data += i * padding
        ax.plot(x_data, data)
    

    【讨论】:

    • This on 与我正在搜索的博客文章很接近,但不完全一样。它完成了事情,但在我接受它正确之前,我想等待其他答案。不过还是谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    相关资源
    最近更新 更多