首页 > 解决方案 > 如何在 Matplotlib 中绘制嵌套的元组列表?

问题描述

我正在努力正确地绘制一个包含一些嵌套列表的列表。这实际上是我计算的输出结果,它们是根据我的输入数据计算出来的。所以,我想根据一对坐标绘制输出。我的样本数据如下:

temp = [(8.30014492234868, 10.076987589320124), 
        (6.565100209934528, 10.126390914006539), 
        (8.064572331389588, 9.999998485114327), 
        (18.801449684428746, 1.1966541400666473), 
        (16.39706266718748, -0.07867904744412477),
        (13.489350431455016, -0.6138733861514962),
        (13.668995714960388, 17.53643661173564), 
        (4.808988910967888, 20.76029261433188), 
        (1.7575932694038692, 14.404108129869353), 
        (3.0136007564635103, 7.318480031628899), 
        (2.988551059917197, 7.355468722551662), 
        (18.826817655400742, 0.30186049637530527),
        (4.9477946187407476, 16.065642524553212), 
        (5.7416001839901165, 5.915851736013389),
        (3.004349636718835, 7.315738092232703),
        ((1.481287160721499, 13.69706806608235), (4.975290244180029, 15.059417315522877)), 
        (9.022336802561307, 8.741822450784232), 
        (8.339683645685863, 9.875063384164433),
        (13.625980549650077, 17.64071625638145), 
        (7.6474833153988016, 20.09172492469006), 
        (9.777767270079616, 1.7478894865558094)]

正如你所看到的,它们都是成对的,可以很容易地绘制出来,除了一个看起来像这样((1.481287160721499, 13.69706806608235), (4.975290244180029, 15.059417315522877))

有时我会得到很多,但我无法正确绘制它们。这是我使用的:

for x, y in temp:
    plt.scatter(x, y, c='k', marker='o', s=4)

for line in temp:
    xll,yll = line.xy
    plt.scatter(xll, yll, color='c', lw=1, zorder=0)

但他们都没有工作。

标签: pythonmatplotlibnested-lists

解决方案


推荐阅读