Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 列表3值的打印列表_Python_Pandas_List_Matplotlib_Plotly - Fatal编程技术网

Python 列表3值的打印列表

Python 列表3值的打印列表,python,pandas,list,matplotlib,plotly,Python,Pandas,List,Matplotlib,Plotly,我有这张名单 c = [[[1.0, 1.0000000000000002, 6154.0], [2.0, 0.0, 6154.0], [3.0, -0.9999999999999997, 6154.0], [4.0, 0.3809523809523809, 6154.0], [5.0, 0.0, 6154.0]], [[1.0, 1.0000000000000002, 3720.0], [2.0, 0.07407407407407404, 3720.0], [3.0,

我有这张名单

c = [[[1.0, 1.0000000000000002, 6154.0],
  [2.0, 0.0, 6154.0],
  [3.0, -0.9999999999999997, 6154.0],
  [4.0, 0.3809523809523809, 6154.0],
  [5.0, 0.0, 6154.0]],
 [[1.0, 1.0000000000000002, 3720.0],
  [2.0, 0.07407407407407404, 3720.0],
  [3.0, 1.0, 3720.0],
  [4.0, 1.0, 3720.0]],
 [[1.0, -1.0000000000000009, 17139.0]],
 [[1.0, -1.0000000000000009, 16149.0]],
 [[1.0, 1.0, 4075.0], [2.0, -0.999999999999999, 4075.0]],
 [[1.0, 0.0, 21445.0],
  [2.0, 1.0000000000000002, 21445.0],
  [3.0, 0.0, 21445.0],
  [4.0, 0.9999999999999998, 21445.0],
  [5.0, 0.0, 21445.0],
  [6.0, 1.0, 21445.0],
  [7.0, 0.0, 21445.0]]]
对于每个列表,我希望使用前两个值绘制散点图,并使用第三个值绘制图例。当我只有两个值时,在这种情况下:

c1 = c = [[[1.0, 1.0000000000000002],
  [2.0, 0.0],
  [3.0, -0.9999999999999997],
  [4.0, 0.3809523809523809],
  [5.0, 0.0]],
 [[1.0, 1.0000000000000002],
  [2.0, 0.07407407407407404],
  [3.0, 1.0],
  [4.0, 1.0]],
 [[1.0, -1.0000000000000009]],
 [[1.0, -1.0000000000000009]],
 [[1.0, 1.0], [2.0, -0.999999999999999]],
 [[1.0, 0.0],
  [2.0, 1.0000000000000002],
  [3.0, 0.0],
  [4.0, 0.9999999999999998],
  [5.0, 0.0],
  [6.0, 1.0],
  [7.0, 0.0]]]
我能够使用以下代码绘制列表列表:

for i in c1:
    plt.plot(*zip(*i), 'o-')
plt.show()


如何修改上面的代码?要达到相同的结果,但使用图例的第三个值?或者您知道如何使用plotly.express进行绘图吗?

我不知道plotly部分,但这是为了在绘图上显示图例:

c1 = list(map(lambda x: list(map(lambda y: y[:2], x)), c))
legend = list(map(lambda x: x[0][-1], c))
for i, lbl in zip(c1, legend):
    plt.plot(*zip(*i), 'o-', label=lbl)
plt.legend(loc="upper left")
plt.show()

我不知道绘图部分,但这是为了在绘图上显示图例:

c1 = list(map(lambda x: list(map(lambda y: y[:2], x)), c))
legend = list(map(lambda x: x[0][-1], c))
for i, lbl in zip(c1, legend):
    plt.plot(*zip(*i), 'o-', label=lbl)
plt.legend(loc="upper left")
plt.show()

使用plotly
,您可以循环浏览列表并使用
名称分别绘制每个子列表

import plotly.graph_objs as go
fig = go.Figure()
for lst in c:
    x, y, g = zip(*lst)
    fig.add_trace(go.Scatter(x=x, y=y, name=g[0]))

fig.show()

使用plotly
,您可以循环浏览列表并使用
名称分别绘制每个子列表

import plotly.graph_objs as go
fig = go.Figure()
for lst in c:
    x, y, g = zip(*lst)
    fig.add_trace(go.Scatter(x=x, y=y, name=g[0]))

fig.show()

你可以用一种简单得多的方法来做:

for i in c:
    plt.plot(*zip(*[j[:2] for j in i] ), 'o-')
plt.gca().legend([i[0][2] for i in c])
plt.show()
您可以使用plt.gca()访问轴的实例。我使用列表理解从原始列表
c
中检索用于绘图和图例的值。
下面是带有图例的结果图:

您可以用一种更简单的方法来完成:

for i in c:
    plt.plot(*zip(*[j[:2] for j in i] ), 'o-')
plt.gca().legend([i[0][2] for i in c])
plt.show()
您可以使用plt.gca()访问轴的实例。我使用列表理解从原始列表
c
中检索用于绘图和图例的值。 下面是带有图例的结果图: