热图错误:与数据帧一起使用时,“NoneType”对象不可调用

Dư *_*Huy 6 python heatmap seaborn

我对seaborn 的热图有这个问题。我不知道如何,但 seaborn.heatmap() 拒绝接受数据帧,而是显示上述错误。Seaborn、matplotlib 和 pandas 是最新的,我在 Visual Studio 上使用 python 3.10。该代码只是seaborn.heatmap本身的示例代码:

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
flights = sns.load_dataset("flights")
flights = flights.pivot("month", "year", "passengers")
ax=sns.heatmap(flights)
plt.show()
Run Code Online (Sandbox Code Playgroud)

rud*_*vic 8

使用 Python 3.9(或 3.8、3.7、3.6),因为pandasplt似乎还没有完全准备好与 Python 3.10 一起使用:

在此输入图像描述

  • 我不知道这是否正确,但在输出中,它说:堆栈跟踪:> File "D:\baitaplaptrinh\lamchoi\PythonApplication1\PythonApplication1\PythonApplication1.py", line 6, in <module> (当前帧) > ax=sns.heatmap(航班) (2认同)