Home > Net >  pandas barplot choose color for each variable
pandas barplot choose color for each variable

Time:10-18

I usually use matplotlib, but was playing with pandas plotting and experienced unexpected behaviour. I was assuming the following would return red and green edges rather than alternating. What am I missing here?

import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({"col1":[1,2,4,5,6], "col2":[4,5,1,2,3]})

def amounts(df):
    fig, ax = plt.subplots(1,1, figsize=(3,4))
    (df.filter(['col1','col2'])
       .plot.bar(ax=ax,stacked=True, edgecolor=["red","green"],
                 fill=False,linewidth=2,rot=0))
    ax.set_xlabel("")
    plt.tight_layout()
    plt.show()

amounts(df)

CodePudding user response:

I think plotting each column separately and setting the enter image description here

  • Related