import pandas as pd
import matplotlib.pyplot as plt
example = pd.DataFrame({'column 1': [0, 1, 0, 1],
'column 2': [1, 0, 1, 0],
'column 3': [1, 1, 0, 0]})
for x, col in enumerate(example.columns):
for y, ind in enumerate(example.index):
if example.loc[ind, col]:
plt.plot(x, y, 'o', color='red')
plt.xticks(range(len(example.columns)), labels=example.columns)
plt.yticks(range(len(example)), labels=example.index)
plt.show()
一种简单的方法是使用两个嵌套循环在每个数据帧单元上有条件地绘制点:
相关问题 更多 >
编程相关推荐