Python 打印日志时出错';matplotlib/scipy/numpy中的d数组
我有两个数组,我获取它们的日志。当我这样做并试图绘制他们的散点图时,我得到了以下错误:Python 打印日志时出错';matplotlib/scipy/numpy中的d数组,python,numpy,matplotlib,scipy,Python,Numpy,Matplotlib,Scipy,我有两个数组,我获取它们的日志。当我这样做并试图绘制他们的散点图时,我得到了以下错误: File "/Library/Python/2.6/site-packages/matplotlib-1.0.svn_r7892-py2.6-macosx-10.6-universal.egg/matplotlib/pyplot.py", line 2192, in scatter ret = ax.scatter(x, y, s, c, marker, cmap, norm, vmin, vma
File "/Library/Python/2.6/site-packages/matplotlib-1.0.svn_r7892-py2.6-macosx-10.6-universal.egg/matplotlib/pyplot.py", line 2192, in scatter
ret = ax.scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, faceted, verts, **kwargs)
File "/Library/Python/2.6/site-packages/matplotlib-1.0.svn_r7892-py2.6-macosx-10.6-universal.egg/matplotlib/axes.py", line 5384, in scatter
self.add_collection(collection)
File "/Library/Python/2.6/site-packages/matplotlib-1.0.svn_r7892-py2.6-macosx-10.6-universal.egg/matplotlib/axes.py", line 1391, in add_collection
self.update_datalim(collection.get_datalim(self.transData))
File "/Library/Python/2.6/site-packages/matplotlib-1.0.svn_r7892-py2.6-macosx-10.6-universal.egg/matplotlib/collections.py", line 153, in get_datalim
offsets = transOffset.transform_non_affine(offsets)
File "/Library/Python/2.6/site-packages/matplotlib-1.0.svn_r7892-py2.6-macosx-10.6-universal.egg/matplotlib/transforms.py", line 1924, in transform_non_affine
self._a.transform(points))
File "/Library/Python/2.6/site-packages/matplotlib-1.0.svn_r7892-py2.6-macosx-10.6-universal.egg/matplotlib/transforms.py", line 1420, in transform
return affine_transform(points, mtx)
ValueError: Invalid vertices array.
代码很简单:
myarray_x = log(my_array[:, 0])
myarray_y = log(my_array[:, 1])
plt.scatter(myarray_x, myarray_y)
你知道这是什么原因吗?谢谢。这对我来说运行得很成功
>>> from numpy import log, array
>>> import matplotlib.pyplot as plt
>>> my_array = array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
>>> my_array
array([[ 1., 2.],
[ 3., 4.],
[ 5., 6.]])
>>> myarray_x = log(my_array[:, 0])
>>> myarray_y = log(my_array[:, 1])
>>> plt.scatter(myarray_x, myarray_y)
<matplotlib.collections.CircleCollection object at 0x030C7A10>
>>> plt.show()
>>来自numpy导入日志,数组
>>>将matplotlib.pyplot作为plt导入
>>>my_array=数组([[1.0,2.0]、[3.0,4.0]、[5.0,6.0])
>>>my_数组
数组([[1,2.],
[ 3., 4.],
[ 5., 6.]])
>>>myarray\u x=log(my\u数组[:,0])
>>>myarray_y=log(my_array[:,1])
>>>plt.散射(myarray_x,myarray_y)
>>>plt.show()
所以也许问题在于你没有给我们看的东西。您能否提供一段完整的示例代码,与您运行时完全相同,以便我们重现您的问题?这对我来说运行成功
>>> from numpy import log, array
>>> import matplotlib.pyplot as plt
>>> my_array = array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
>>> my_array
array([[ 1., 2.],
[ 3., 4.],
[ 5., 6.]])
>>> myarray_x = log(my_array[:, 0])
>>> myarray_y = log(my_array[:, 1])
>>> plt.scatter(myarray_x, myarray_y)
<matplotlib.collections.CircleCollection object at 0x030C7A10>
>>> plt.show()
>>来自numpy导入日志,数组
>>>将matplotlib.pyplot作为plt导入
>>>my_array=数组([[1.0,2.0]、[3.0,4.0]、[5.0,6.0])
>>>my_数组
数组([[1,2.],
[ 3., 4.],
[ 5., 6.]])
>>>myarray\u x=log(my\u数组[:,0])
>>>myarray_y=log(my_array[:,1])
>>>plt.散射(myarray_x,myarray_y)
>>>plt.show()
所以也许问题在于你没有给我们看的东西。您能否提供一段与您运行时完全相同的完整示例代码,以便我们重现您的问题?新答案: 从源代码来看,如果传入仿射_变换的点数组的维数错误或为空,则会引发此错误。以下是相关线路:
if (!vertices ||
(PyArray_NDIM(vertices) == 2 && PyArray_DIM(vertices, 1) != 2) ||
(PyArray_NDIM(vertices) == 1 && PyArray_DIM(vertices, 0) != 2))
throw Py::ValueError("Invalid vertices array.");
在继续之前,请先查看myarray_x和myarray_y数组的维度
旧答案:
我最好的猜测是你正在记录价值观新答案: 从源代码来看,如果传入仿射_变换的点数组的维数错误或为空,则会引发此错误。以下是相关线路:
if (!vertices ||
(PyArray_NDIM(vertices) == 2 && PyArray_DIM(vertices, 1) != 2) ||
(PyArray_NDIM(vertices) == 1 && PyArray_DIM(vertices, 0) != 2))
throw Py::ValueError("Invalid vertices array.");
在继续之前,请先查看myarray_x和myarray_y数组的维度
旧答案:
我的最佳猜测是您正在使用值日志我最近解决了相同的问题: 我的问题是,我的X和Y(numpy)数组由128位浮点组成 这种情况下的解决方案是将阵列重铸为较低精度的浮点值,即
array=numpy.float64(数组)
希望这有帮助:~)我最近解决了同样的问题: 我的问题是,我的X和Y(numpy)数组由128位浮点组成 这种情况下的解决方案是将阵列重铸为较低精度的浮点值,即
array=numpy.float64(数组)
希望这有帮助:~)您需要指定更多信息。例如,在调用
plt.scatter
之前,查看myarray\u x
,myarray\u y
,您需要指定更多信息。例如,在调用plt.scatter之前查看myarray\u x
,myarray\u y
。。。。这听起来像是“ValueError:Invalid vertices array.”试图说的。@Jusint:No。当plotting@Justin,这是有道理的,但pyplot不是这样做的;至少在正常情况下,pyplot会忽略这些值。例如,如果我尝试使用my_array=array([[1.0,2.0],[3.0,4.0],-5.0,0.0]])
进行复制,它不会为我发出此错误,而是仅用两个点绘制图形。叮叮。。。。这听起来像是“ValueError:Invalid vertices array.”试图说的。@Jusint:No。当plotting@Justin,这是有道理的,但pyplot不是这样做的;至少在正常情况下,pyplot会忽略这些值。例如,如果我通过尝试使用my_array=array([[1.0,2.0],[3.0,4.0],-5.0,0.0]])
运行,它不会为我发出此错误,而是画一个只有两点的图表。事实上,我认为这是正确的答案。至少它解决了我的问题。事实上,这是正确的答案。至少它解决了我的问题。