Search code examples
pythonmatplotlibgraphseaborncategorical-data

How To plot a discrete categorical dataframe


I am trying to plot a graph like this of the CSV file drive link in python. I looked upon alot of tutorials of seaborn and matplotlib but can't figure out a way to do this. I also tried iterating the rows still didn't work. Any help will be highly appreciated. sample Dataframe:

clr CYS ASP SER GLN LYS ILE PRO
2rh1_0 1 0 0 0 0 1 1
2rh1_1 0 0 0 0 0 1 0
2rh1_2 0 0 0 0 1 0 0
3D4S_0 1 0 1 0 1 0 0

Solution

  • You're looking for a scatter plot like this:

    import matplotlib.pyplot as plt
    
    data = {'apples': 'sweet', 'oranges': 'both', 'lemons': 'sour', 'limes': 'sour', 'strawberries': 'sweet'}
    names = list(data.keys())
    values = list(data.values())
    
    plt.scatter(data.keys(), data.values())
    plt.show()
    

    a scatter plot

    Note: the data clearly doesn't have to be in a dictionary, I'm passing it as two iterables when calling plt.scatter, so it could be in two lists, a list of tuples, etc.