1

I have a Pandas dataframe that looks like:

    0  1  2  3  4 
0   1  1  1  0  1
1   1  0  1  1  1
2   1  0  0  1  0
3   1  1  1  0  0
4   0  1  0  0  0

and I want to create a plot of this data (maybe using matplotlib) that looks like:

x  x  x     x
x     x  x  x
x        x  
x  x  x  
   x  

Does anyone know of a way to do this? The plot does not need to be generated by matplotlib

lizard6
  • 65
  • 1
  • 9

2 Answers2

1
import matplotlib.pyplot as plt
import numpy as np

a = np.array([[1,1,1],[1,0,1],[0,1,0]])
print(a)
af = np.flipud(a) ### flip upside down, get the right coordinates in the scatter plot
args = np.argwhere(af) ### find the args where we do not have zeros
plt.figure(figsize=(3,3))
plt.scatter(args.T[1,:],args.T[0,:], marker="x"); #plot!

enter image description here

kabrapankaj32
  • 4,700
  • 1
  • 16
  • 21
0

This might get you on the right track.

import matplotlib.pyplot as plt
points = []
for index, row in df.iterrows():
    for i,x in enumerate(row):
        if x==1:
            points.append([index,i])
df_plt = pd.DataFrame(points)
plt.scatter(df_plt[0],df_plt[1])
plt.show()
Chris
  • 12,661
  • 3
  • 20
  • 33