如何在python中将具有不同列长度的数据表转换为箱线图

如何在python中将具有不同列长度的数据表转换为箱线图,python,numpy,matplotlib,statistics,Python,Numpy,Matplotlib,Statistics,我正试图绘制一组数据。下面是一个示例 34456.11718 34767.75017 34392.43452 34356.77702 34552.49424 34618.99645 34845.01827 34470.82192 34755.43286 34490.34788 34524.72989 34838.92508 34464.9628 34685.11467 34583.76757 34525.16889 34837.37895 34541.02059 34555.63599 345

我正试图绘制一组数据。下面是一个示例

34456.11718 34767.75017 34392.43452 34356.77702 34552.49424
34618.99645 34845.01827 34470.82192 34755.43286 34490.34788
34524.72989 34838.92508 34464.9628  34685.11467 34583.76757
34525.16889 34837.37895 34541.02059 34555.63599 34527.23146
34531.52852 34770.05856 34568.93382 34504.1442  34514.08938
34431.45985 34585.67336 34527.43138 34071.39518 34533.3499
34329.05653 34536.24601 34606.97121 34132.64443 34439.45988
34268.17505 34611.81836 34608.9584  34075.29279 34474.64524
34477.37305 34699.84967 34646.87148 33802.50334 34441.68268
34674.54769 34632.93716 34672.11406 33906.01839 34457.02467
34576.99168 34722.83457 34548.2877  34040.83828 34531.64214
34534.72687 34633.32703 34627.64169 34370.23821 34520.28533
34598.89338 34598.50237 34717.49512 34415.73371 34426.95518
34462.53642 34549.27221 34663.26121 34114.69248 34375.88882
34385.24535 34549.24708 34713.14059 33865.1237  
34429.79659 34538.31632 34716.97048 34280.39958 
34652.65947 34523.53762 34698.31976 34492.3672  
34645.35515 34546.5272  34598.81003 34531.15127 
34630.22884 34591.32164 34597.6796  34362.6228  
34720.29415 34451.27535 34746.00718 34233.68801 
34645.84702             34636.53923 34031.19302 
34389.24407             34134.58745 34431.07515
实际数组要长得多,但关键特性是它有5列,每个列在不同的文本文件中命名。这是我的密码:

import numpy as np

import matplotlib.pyplot as plt


plt.show()

tube1data = np.genfromtxt("speed1.txt")
tube2data = np.genfromtxt("speed2.txt")
tube3data = np.genfromtxt("speed3.txt")
tube4data = np.genfromtxt("speed4.txt")
tube5data = np.genfromtxt("speed5.txt")

plt.boxplot(tube1data,patch_artist=True)
plt.boxplot(tube2data,patch_artist=True)
plt.boxplot(tube3data,patch_artist=True)
plt.boxplot(tube4data,patch_artist=True)
plt.boxplot(tube5data,patch_artist=True)


plt.show()

箱线图
将很高兴地绘制一系列数据分布。它们不需要相同的长度

就你而言:

plt.boxplot([tube1data, tube2data, <...>], patch_artist=True)

那么问题出在哪里呢?函数
plt.boxplot()
还使用
positions
关键字参数来设置要显示的数据的x轴位置。
import numpy as np
import matplotlib.pyplot as plt

lengths = [100, 10, 200, 20, 50]
dists = [np.random.normal(0, 1, n) for n in lengths]

fig, ax = plt.subplots()
ax.boxplot(dists, patch_artist=True)
plt.show()