Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.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时出错_Python_Matplotlib - Fatal编程技术网

Python编程,使用matplotlib时出错

Python编程,使用matplotlib时出错,python,matplotlib,Python,Matplotlib,在ipython笔记本中运行此代码时 import matplotlib.pyplot as pl x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] plt.plot(x, y) plt.plot(x, y) plt.ylabel('Doubles') 我面对这些错误: TypeError Traceback (most recent call last) <ipython-input-

在ipython笔记本中运行此代码时

import matplotlib.pyplot as pl
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

plt.plot(x, y)

plt.plot(x, y)

plt.ylabel('Doubles')
我面对这些错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-4-f244d65cd40c> in <module>()
      1 x={1,2,3,4,5}
      2 y={2,4,6,8,10}
----> 3 plt.plot(x,y)

/usr/local/lib/python3.5/dist-packages/matplotlib/pyplot.py in plot(*args, **kwargs)
   3315                       mplDeprecation)
   3316     try:
-> 3317         ret = ax.plot(*args, **kwargs)
   3318     finally:
   3319         ax._hold = washold

/usr/local/lib/python3.5/dist-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1896                     warnings.warn(msg % (label_namer, func.__name__),
   1897                                   RuntimeWarning, stacklevel=2)
-> 1898             return func(ax, *args, **kwargs)
   1899         pre_doc = inner.__doc__
   1900         if pre_doc is None:

/usr/local/lib/python3.5/dist-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
   1405 
   1406         for line in self._get_lines(*args, **kwargs):
-> 1407             self.add_line(line)
   1408             lines.append(line)
   1409 

/usr/local/lib/python3.5/dist-packages/matplotlib/axes/_base.py in add_line(self, line)
   1791             line.set_clip_path(self.patch)
   1792 
-> 1793         self._update_line_limits(line)
   1794         if not line.get_label():
   1795             line.set_label('_line%d' % len(self.lines))

/usr/local/lib/python3.5/dist-packages/matplotlib/axes/_base.py in _update_line_limits(self, line)
   1813         Figures out the data limit of the given line, updating self.dataLim.
   1814         """
-> 1815         path = line.get_path()
   1816         if path.vertices.size == 0:
   1817             return

/usr/local/lib/python3.5/dist-packages/matplotlib/lines.py in get_path(self)
    987         """
    988         if self._invalidy or self._invalidx:
--> 989             self.recache()
    990         return self._path
    991 

/usr/local/lib/python3.5/dist-packages/matplotlib/lines.py in recache(self, always)
    674                 x = ma.asarray(xconv, np.float_).filled(np.nan)
    675             else:
--> 676                 x = np.asarray(xconv, np.float_)
    677             x = x.ravel()
    678         else:

/usr/local/lib/python3.5/dist-packages/numpy/core/numeric.py in asarray(a, dtype, order)
    529 
    530     """
--> 531     return array(a, dtype, copy=False, order=order)
    532 
    533 

TypeError: float() argument must be a string or a number, not 'set'

我不确定这些错误是什么,为什么会出现?我使用了Ipython的2和3个python版本,但在这两种情况下,类似的错误仍然存在。如何纠正这些错误?谢谢,回溯显示您已将变量定义为集合,而不是列表。plt.plot函数需要列表


在定义变量时,请确保使用括号而不是大括号。也就是说,x=[1,2,3,4,5],而不是x={1,2,3,4,5}

错误消息中的代码与发布的代码不匹配。使用方括号[]表示列表,在回溯中使用大括号{}表示集合。第一种方法是正确的