Reputation:
I was trying to plot a bar diagram with first 10 bars green and last 10 bars red colors.
Here is my code:
import pandas as pd
import numpy as np
df = pd.DataFrame({'c0':np.arange(20)})
my_colors = ['g','g','g','g','g',
'g','g','g','g','g',
'r','r','r','r','r',
'r','r','r','r','r']
df.plot(kind='bar', color=my_colors)
How can the problem be solved?
pd.__version__
'0.23.4'
Upvotes: 5
Views: 1647
Reputation: 165
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.DataFrame({'c0':np.arange(20)})
my_colors = ['g','g','g','g','g',
'g','g','g','g','g',
'r','r','r','r','r',
'r','r','r','r','r']
for i ,row in enumerate(my_colors):
plt.bar(i,df.loc[i,"c0"],color=row)
Upvotes: 0
Reputation: 7341
Color has to be a list with list inside. try:
df = pd.DataFrame({'c0':np.arange(20)})
# attention to double "["
my_colors = [['g','g','g','g','g',
'g','g','g','g','g',
'r','r','r','r','r',
'r','r','r','r','r']]
df.plot(kind='bar', color=my_colors)
Also this issue can help
Upvotes: 7