Matplotlib绘图条形图时出现“float() argument must be a string or a number, not 'NoneType'”错误。

4
我将展示代码的相关部分。
import matplotlib.pyplot as plt
tacf = pd.DataFrame(data_acf)
print (type(tacf))
plt.bar(tacf,height=2.0)
plt.show()

输出

<class 'pandas.core.frame.DataFrame'>
  File "/home/jh/miniconda3/lib/python3.6/site-packages/matplotlib/patches.py", line 351, in set_linewidth
    self._linewidth = float(w)
TypeError: float() argument must be a string or a number, not 'NoneType'

如果我选择 tacf.head。
<bound method NDFrame.head of            0
0   1.000000
1   0.942361
2   0.863303
3   0.794420
4   0.727603
5   0.671579
6   0.622612
7   0.570949
8   0.529410
9   0.497035
10  0.485163
11  0.479443
12  0.461094
13  0.444726
14  0.436634

我对bars、args和kwargs感到困惑。我应该将dataframe转换为不同类型还是...?

如何使用Matplotlib将dataframe绘制成条形图?


1
tacf.head() 返回任何数据吗? - O.Suleiman
tacf.head() 的翻译是:tacf.head() - DYZ
1个回答

2

既然您有pandas数据框,那么您可以使用它的绘图方法:

tacf.plot(kind='bar')

您的数据结果:

在此输入图片描述

这相当于:

plt.bar(tacf.index, tacf.iloc[:, 0])
plt.legend(tacf.columns)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接