Neuhneuh
Neuhneuh

Reputation: 11

Pandas Pivot Table and Matplotlib bar

I'm trying to use Matplotlib to make a Bar graph with different color. So far, I have a Pandas Pivot Table which looks like this:

              productType
physicalType             
Chassis                54
Fan                   295
Module                154
Power Supply           91

I can get a Bar graph but the color are all the same for each series. How can I have different colors for different series ?

Thanks,

Upvotes: 1

Views: 1610

Answers (1)

Scott Boston
Scott Boston

Reputation: 153460

One way you could do it is to use T and pandas plot:

df.T.plot.bar()

enter image description here

Another way is to use itertuples:

import matplotlib.pyplot as plt
df1 = df.reset_index()
fig, ax = plt.subplots()
for r in df1.itertuples():
    ax.bar(r[0],r[2],label=r[1])

_ = plt.xticks(df1.index,df1.physicalType)

enter image description here

Upvotes: 1

Related Questions