Python 在一系列数字上绘制数字列表

Python 在一系列数字上绘制数字列表,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有一个如下所示的数据框: Season Dist 0 '14 - '15 [120, 128, 175, 474, 615] 1 '15 - '16 [51, 305, 398, 839, 991, 1093, 1304] 2 '16 - '17 [223, 293, 404, 588, 661, 706, 964, 1049, 1206] 3 '17 - '18 [12, 37, 204, 229, 2

我有一个如下所示的数据框:

        Season      Dist
0   '14 - '15       [120, 128, 175, 474, 615]
1   '15 - '16       [51, 305, 398, 839, 991, 1093, 1304]
2   '16 - '17       [223, 293, 404, 588, 661, 706, 964, 1049, 1206]
3   '17 - '18       [12, 37, 204, 229, 276, 349, 809, 845, 1072, 1...
4   '18 - '19       [210, 214, 259, 383, 652, 798, 1150]
5   '19 - '20       [182, 206, 221, 282, 283, 297, 1330, 1332]
我试图用matplotlib绘制它,其中x轴是实例的范围,对于y轴上的每个季节,该图显示
df['Dist']
的分布。我在下面画了一个非常糟糕的图表来说明我的观点


有人知道我是如何做到这一点的吗?

在同一个图表上分别绘制每个列表。列表值将用作x坐标,因此对于y坐标,将每个季节的值映射为整数。i、 像这样的东西

        Season      Dist
0        0       [120, 128, 175, 474, 615]
1        1       [51, 305, 398, 839, 991, 1093, 1304]
2   '    2       [223, 293, 404, 588, 661, 706, 964, 1049, 1206]  
    y                      x
[0,0,0,0,0]           [120, 128, 175, 474, 615]
[1,1,1,1,1,1,1]       [51, 305, 398, 839, 991, 1093, 1304]  

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.DataFrame({'Season':['14 - 15','15 - 16','16 - 17'],'Dist':\
                   [[120, 128, 175, 474, 615],\
                    [51, 305, 398, 839, 991, 1093, 1304],\
                    [223, 293, 404, 588, 661, 706, 964, 1049, 1206]]})

y = np.arange(len(df)) #map the seasons

for i in range(len(df)):
    plt.scatter(df['Dist'][i],[y[i] for j in range(len(df['Dist'][i]))]) #create a list of y coordinates for every x coordinate
plt.yticks(y,df['Season']) #show the actual seasons as xticks
plt.show()
现在,散点图需要每个x坐标的y坐标。
所以,创建这样的东西

        Season      Dist
0        0       [120, 128, 175, 474, 615]
1        1       [51, 305, 398, 839, 991, 1093, 1304]
2   '    2       [223, 293, 404, 588, 661, 706, 964, 1049, 1206]  
    y                      x
[0,0,0,0,0]           [120, 128, 175, 474, 615]
[1,1,1,1,1,1,1]       [51, 305, 398, 839, 991, 1093, 1304]  

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.DataFrame({'Season':['14 - 15','15 - 16','16 - 17'],'Dist':\
                   [[120, 128, 175, 474, 615],\
                    [51, 305, 398, 839, 991, 1093, 1304],\
                    [223, 293, 404, 588, 661, 706, 964, 1049, 1206]]})

y = np.arange(len(df)) #map the seasons

for i in range(len(df)):
    plt.scatter(df['Dist'][i],[y[i] for j in range(len(df['Dist'][i]))]) #create a list of y coordinates for every x coordinate
plt.yticks(y,df['Season']) #show the actual seasons as xticks
plt.show()

像这样的吗?我只策划了两个季节,你自己先走一步。然后,如果你不能让你的代码做你想做的事情,就展示你的代码。有一些非常简单的例子可以让你进入@Julkar9是的,这正是我想要的!你是怎么做到的?@Bill我试过做这样的事情
plt.plot(list(df['Dist'])、list(df['seasure'])plt.axis([01500])plt.show()
,但没有成功