Matplotlib:scatter无法绘制十进制值

时间:2014-07-15 17:21:20

标签: python matplotlib plot

我正在使用matplotlib生成散点图。我需要绘制的大部分值都是Decimal s,但matplotlib无法绘制Decimal值。它说ValueError: Invalid vertices array.

有解决方法吗?

import numpy as np
import matplotlib.pyplot as plt
from decimal import *

def plotGraph(dic, name):
   x = []
   y = []
   xlabels = []
   xVal = 1
   for testcase in dic:
      for value in dic[testcase]:
          x.append(xVal)
          y.append(value)
          xlabels.append('test '+str(testcase))
      xVal = xVal+1
   plt.ylabel(name)
   plt.title('Scores by testcases')
   plt.xticks(x, xlabels, rotation=90)
   area = 20 # 0 to 15 point radiuses
   plt.tight_layout()
   plt.scatter(x, y, s=area, alpha=0.5)
   plt.savefig('example.png')

dic = {100224L: [Decimal('1069.932'), Decimal('1070.523')],
         100221L: [Decimal('1069.932'), Decimal('1060.523')]}
plotGraph(dic, 'Hello')

我断定matplotlib无法绘制Decimals,因为当我将行y.append(value)更改为y.append(int(value))时,我能够看到该情节。

0 个答案:

没有答案