如何在索引为字符串的地方绘制图形

问题描述 投票:2回答:1

我正在使用python 3.7.6,并且具有以下dataframe

         col_1  col_2  col_3  col_4
GP           1      1      1      1
MIN          1      1      1      1
PTS          1      1      1      1
FGM          1      1      0      1
FGA          0      1      0      0
FG%          0      1      1      1
3P Made      0      1      1      0
AST          0      1      1      0
STL          0      1      0      0
BLK          0      1      1      0
TOV          0      0      1      0

我想将dataframe绘制为scatter plot or other (dot's plot),其中:

X轴-数据框索引

Y轴-数据框列

图形上的点是根据dataframe中的值(1-显示在图形上,而不是0)

我该怎么办?

python pandas
1个回答
0
投票

我不确定分散性,但是您可以使用imshow显示二进制值:

fig, ax = plt.subplots()
ax.imshow(df, cmap='gray')
ax.set_xticks(range(df.shape[1]))
ax.set_xticklabels(df.columns)

ax.set_yticks(range(df.shape[0]))
ax.set_yticklabels(df.index)
plt.show()

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.