Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.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 MatPlotLib:将多个y值分散到一个x值,并使用回归线_Python_Matplotlib_Types - Fatal编程技术网

Python MatPlotLib:将多个y值分散到一个x值,并使用回归线

Python MatPlotLib:将多个y值分散到一个x值,并使用回归线,python,matplotlib,types,Python,Matplotlib,Types,我想在matplotlib中创建散点图来衡量我的算法的性能 我的数据示例如下: x = [1, 2, 3, 4, 5] y1 = [1, 2, 3] # corresponding to x = 1 y2 = [4, 5, 6] # corresponding to x = 2 y3 = [7, 8, 9] # corresponding to x = 3 y4 = [10, 11, 12] # corresponding to x = 4 y5 = [13, 14, 15]

我想在matplotlib中创建散点图来衡量我的算法的性能

我的数据示例如下:

x = [1, 2, 3, 4, 5]
y1 = [1, 2, 3]    # corresponding to x = 1
y2 = [4, 5, 6]    # corresponding to x = 2
y3 = [7, 8, 9]    # corresponding to x = 3
y4 = [10, 11, 12] # corresponding to x = 4
y5 = [13, 14, 15] # corresponding to x = 5
用一个x值表示多个y值的最佳数据类型是什么


在我的例子中,这种关系是指数关系。有没有办法在matplotlib中绘制指数回归线?

我认为这与数据分析有关。如果我理解正确,我认为您希望对每个测试的时间效率进行比较,但在每个测试运行时,它们应该位于相同的测试环境(如相同的机器、相同的输入数据等),因此只要给出一个建议,您就可以使用每个测试的平均运行时间作为标准值来显示测试结果。下面是一些您可以使用的代码

import numpy as np
import matplotlib.pyplot as plt

data_dim = 4 # number of test
data_points = 100 # number of each test_data_points

data_set = np.random.rand(data_dim,data_points)
time = [ list(range(len(i))) for i in data_set]

norm = np.full((data_dim,data_points),1)
aver = [] # get each test's average value
ndx = 0
for i in norm:
    aver.append(i* sum(data_set[0]) / data_points)


fig = plt.figure(figsize=(10,10))

ndx = 1
for i in range(0,2):
    for j in range(0,2):
        ax = fig.add_subplot(2,2,ndx)
        ax.plot(time[ndx-1],data_set[ndx-1],'ko')
        ax.plot(time[ndx-1],aver[ndx-1],'r')
        ax.set_ylim(-1,2)
        ndx += 1

plt.show()
以下是运行结果。请注意,红色实线是您的平均测试时间,这将为您的每次测试提供一些感觉。