无法在jupyter笔记本中绘制图形matplotlib

时间:2017-11-15 06:45:46

标签: matplotlib

即时通讯使用新笔记本电脑并将旧数据传输到新笔记本电脑。但是我的matplotlib不想在新窗口中绘制图形,但它适用于旧窗口。我检查了matplotlib的安装和一切,不知道出了什么问题

import numpy as np
import matplotlib.pyplot as pl

#creating list
pd = {0.05, 0.34, 0.56, 0.5, 0.7,0.2, 0.36, 0.54, 0.65, 0.456}
#len of the lists
d = len (pd)
print (d)

x = range(d)
bwidth= 1/1.25
pl.figure(1,figsize =(7,5))
pl.bar(x,pd,bwidth, color = "red")
pl.show()

这是我得到的错误

TypeError                                 Traceback (most recent call last)
<ipython-input-12-b7b3df1db861> in <module>()
     12 bwidth= 1/1.25
     13 pl.figure(1,figsize =(7,5))
---> 14 pl.bar(x,pd,bwidth, color = "red")
     15 pl.show()

 C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py in 
 bar(*args, **kwargs)
 2625                       mplDeprecation)
 2626     try:
->2627         ret = ax.bar(*args, **kwargs)
 2628     finally:
 2629         ax._hold = washold

 C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py in 
 inner(ax, *args, **kwargs)
  1708                     warnings.warn(msg % (label_namer, func.__name__),
  1709                                   RuntimeWarning, stacklevel=2)
->1710             return func(ax, *args, **kwargs)
  1711         pre_doc = inner.__doc__
  1712         if pre_doc is None:

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in 
bar(self, *args, **kwargs)
   2154             elif orientation == 'horizontal':
   2155                 r.sticky_edges.x.append(l)
-> 2156             self.add_patch(r)
   2157             patches.append(r)
   2158 

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in 
add_patch(self, p)
   1832         if p.get_clip_path() is None:
   1833             p.set_clip_path(self.patch)
-> 1834         self._update_patch_limits(p)
   1835         self.patches.append(p)
   1836         p._remove_method = lambda h: self.patches.remove(h)

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in 
_update_patch_limits(self, patch)
   1852         vertices = patch.get_path().vertices
   1853         if vertices.size > 0:
-> 1854             xys = patch.get_patch_transform().transform(vertices)
   1855             if patch.get_data_transform() != self.transData:
   1856                 patch_to_data = (patch.get_data_transform() -

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\patches.py in 
get_patch_transform(self)
    720 
    721     def get_patch_transform(self):
--> 722         self._update_patch_transform()
    723         return self._rect_transform
    724 

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\patches.py in 
_update_patch_transform(self)
    713         width = self.convert_xunits(self._width)
    714         height = self.convert_yunits(self._height)
--> 715         bbox = transforms.Bbox.from_bounds(x, y, width, height)
    716         rot_trans = transforms.Affine2D()
    717         rot_trans.rotate_deg_around(x, y, self.angle)

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\transforms.py in 
from_bounds(x0, y0, width, height)
    802         *width* and *height* may be negative.
    803         """
--> 804         return Bbox.from_extents(x0, y0, x0 + width, y0 + height)
    805 
    806     @staticmethod

TypeError: unsupported operand type(s) for +: 'int' and 'set'

即时通讯使用matplotlib 2.1.0版本和Python 3.6.3

1 个答案:

答案 0 :(得分:0)

你无法绘制集合。在上面的代码中,pd是一个集合,而不是列表。

您可以在绘图之前先转换为列表,

plt.bar(x, list(pd), bwidth, color = "red")
相关问题