Function to create grouped bar plot

前端 未结 2 1504
北恋
北恋 2020-12-05 11:12

The goal here is to create a grouped bar plot, not subplots like the image below

Is there a simple way to create a grouped bar plot in Python? Right

2条回答
  •  不知归路
    2020-12-05 11:49

    You can simply do this using the code given below:

    import pandas as pd
    import matplotlib.pyplot as plt
    
    positive_values = [20, 17.5, 40]
    negative_values = [15, 8, 70]
    index = ['Precision', 'Recall', 'f1-score',]
    df = pd.DataFrame({'Positive Values': positive_values,
                        'Negative Values': negative_values}, index=index)
    ax = df.plot.bar(rot=0, color={"Positive Values": "green", "Negative Values": "red"})
    

    Output:

提交回复
热议问题