Search code examples
pythonplotdata-visualizationcategorical-data

Is it possible to plot a chart in python where both the x axis and y axis are categorical?


I would like to make a bubble chart out of this dataframe that shows gaps or frequencies of missing values in data analysis.

Is it possible to list field names or categorical values on the x axis and the plot the number of missing by different locations on the y axis?

Or do I need to create subplots for each location?

                 |Targeted Start Date  |Targeted End Date  |Projected End Date  
Location         | ------------------- | ----------------- | -----------------                    
Q                |                  0  |                0  |                 0   
R                |                  6  |                7  |               113   
V                |                  1  |                1  |                 6   
Z                |                  0  |                0  |                 0  

Solution

  • import altair as alt
    import pandas as pd
    import numpy as np
    d1 = {'Location': ['Q', 'R', 'V', 'Z'], 'Targeted Start Date': [0, 6, 1 ,0], 'Targeted End Date': [0, 7, 1 ,0], 'Targeted End Date': [0, 113, 6 ,0]}
    
    df = pd.DataFrame.from_dict(d1)
    
    #df = df.set_index('Location')
    
    print(df)
    
    dfMelt = df.melt(id_vars='Location', value_name='MissingItemCnt', var_name='FieldName')
    
    print(dfMelt)
    
    alt.Chart(dfMelt).mark_point().encode(x = 'FieldName', y = 'Location', size = 'MissingItemCnt')
    

    enter image description here