Reputation: 10373
I´m working on some EDA with python using pandas to make the plots. The default forman for the plots looks like this:
But if I made some more complex filtering, like this:
s = (coupon_list[[ 'USABLE_DATE_MON', 'USABLE_DATE_TUE', 'USABLE_DATE_WED',
'USABLE_DATE_THU', 'USABLE_DATE_FRI', 'USABLE_DATE_SAT',
'USABLE_DATE_SUN','DISCOUNT_PRICE']].melt("DISCOUNT_PRICE", var_name='days', value_name='data')
.assign(days = lambda x: pd.Categorical(x['days'],
ordered=True,
categories=days))
.query('data == 1')
.groupby("days")['DISCOUNT_PRICE']
.mean())
s.plot.bar()
The format changes to a carnival
Now I don´t know how to plot it in the same format than the rest of the images.
I tried with the addition argument cmap:
s = (coupon_list[[ 'USABLE_DATE_MON', 'USABLE_DATE_TUE', 'USABLE_DATE_WED',
'USABLE_DATE_THU', 'USABLE_DATE_FRI', 'USABLE_DATE_SAT',
'USABLE_DATE_SUN','DISCOUNT_PRICE']].melt("DISCOUNT_PRICE", var_name='days', value_name='data')
.assign(days = lambda x: pd.Categorical(x['days'],
ordered=True,
categories=days))
.query('data == 1')
.groupby("days")['DISCOUNT_PRICE']
.mean())
s.plot.bar(cmap='Blues_r')
But I'm not findding the same colors there:
Upvotes: 1
Views: 192
Reputation: 59549
What you're seeing is the difference in plotting a DataFrame
versus a Series
when using a bar
plot. You can use s.to_frame().plot.bar()
to turn you Series
into a DataFrame
before you plot to get a single color:
import pandas as pd
import numpy as np
df = pd.DataFrame({'col1': np.random.randint(1,10,20)})
df[['col1']].plot(kind='bar')
df['col1'].plot(kind='bar')
You can see that in the case of bar plot with a DataFrame
the color is a single value per Series
and the Series
are labeled by the column names. When you do a bar
plot with a Series, a new color is cycled for each index, and no labels are provided by default.
Upvotes: 1