首页 > 解决方案 > python seaborn 热图

问题描述

我正在尝试使用我自己的数据集从以下内容重新创建以下热图:

https://seaborn.pydata.org/examples/heatmap_annotation.html

我收到以下错误:

calc_data = plot_data.data[~np.isnan(plot_data.data)] TypeError: ufunc 'isnan' not supported for the input types, a

任何帮助解决它将不胜感激。数据似乎可以正确加载和旋转,但可能不是正确的 dtype。

谢谢,

蒂姆

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd

sns.set()

# Load the example flights dataset and convert to long-form

flights_long = pd.read_csv("Data.csv")

flights = flights_long.pivot("month", "year", "passengers")


# Draw a heatmap with the numeric values in each cell

f, ax = plt.subplots(figsize=(9, 6))
sns.heatmap(flights, annot=True, fmt="d", linewidths=.5, ax=ax)
plt.show()

标签: pythonpandasseaborn

解决方案


推荐阅读