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
  • 10

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

pka32
  • 5,176
  • 1
  • 17
  • 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
  • 15,819
  • 3
  • 24
  • 37