针对多维数组绘制一维数组?

时间:2014-08-21 03:25:46

标签: python arrays multidimensional-array

考虑以下代码:

   import matplotlib.pyplot as plt
   x = [[512],[256],[1024],[2048],[4096],[8192],[32768],
       [65536],[131072]]
   y =[[900,1800],[ 600, 900, 1800, 2700,3600],
      [1800],[900,1800,3600,6000,7200,10800,12000,14400,28800],
      [900, 1800, 3600, 5400, 6000, 7200, 36000],
      [600, 900, 1200, 1800, 2700, 3600, 5400, 6000, 7200, 9600, 18000, 36000],
      [1800, 2700, 3600, 4800, 5400, 6000, 7200, 10800, 18000],
      [1800, 2700, 3600, 5400, 7200, 10800, 21600],[900, 1800, 3600, 7200]]

   fig = plt.figure()

   graph = fig.add_subplot(111)
   for i in range(len(x)):
     plt.plot(x[i], y[i], color='blue', lw=1, marker='s')
   plt.title('userid_22')
   plt.xlabel('Processors')
   plt.ylabel('Est_runtime')

   plt.savefig('processor-esttimeanalysis4.png')
   plt.show()

我收到以下错误:

    ValueError: x and y must have same first dimension

如果有人建议如何正确地绘制它会有帮助吗?

1 个答案:

答案 0 :(得分:1)

你没有确切地说出你真正希望它做什么,但也许你打算

   import matplotlib.pyplot as plt
   x = [[512],[256],[1024],[2048],[4096],[8192],[32768],
       [65536],[131072]]
   y =[[900,1800],[ 600, 900, 1800, 2700,3600],
      [1800],[900,1800,3600,6000,7200,10800,12000,14400,28800],
      [900, 1800, 3600, 5400, 6000, 7200, 36000],
      [600, 900, 1200, 1800, 2700, 3600, 5400, 6000, 7200, 9600, 18000, 36000],
      [1800, 2700, 3600, 4800, 5400, 6000, 7200, 10800, 18000],
      [1800, 2700, 3600, 5400, 7200, 10800, 21600],[900, 1800, 3600, 7200]]

   fig = plt.figure()

   graph = fig.add_subplot(111)
   for x_value, y_value in zip(x, y):
       plt.plot(x_value * len(y_value), y_value, color='blue', lw=1, marker='s')
   plt.title('userid_22')
   plt.xlabel('Processors')
   plt.ylabel('Est_runtime')

   plt.savefig('processor-esttimeanalysis4.png')
   plt.show()