2

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

light picture

2 Answers 2

1

Try changing the last line to df['count'].plot.bar(color=colors)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

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)

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.