Reputation: 17164
There are many bar plot questions of similar question here in stackoverflow, but none of them completely answer the question.
I have a pandas dataframe and want to use pandas bar plot with increasing hue of given color (e.g. Blue, Red).
Here is my code:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import seaborn as sns
df = pd.DataFrame({'count': {0: 3372, 1: 68855, 2: 17948, 3: 708, 4: 9117}})
norm = plt.Normalize(0, df["count"].values.max())
colors = plt.cm.Blues(norm(df["count"].values))
df.plot(kind='bar', color=colors);
Required
Slightly blue color to lowest value.
Darkest blue color to maximum value.
Related questions:
How to give a pandas/matplotlib bar graph custom colors
Change colours of Pandas bar chart
Upvotes: 2
Views: 1741
Reputation: 3001
The problem here is you are calling .plot()
on df
, which is a pd.DataFrame
, and not on a pd.Series
. Try this:
df['count'].plot(kind='bar', color=colors)
Upvotes: 1
Reputation: 588
Try changing the last line to df['count'].plot.bar(color=colors)
Upvotes: 1