0

I have a problem about defining many color in legend part of bar graph.

After I've done some essential process, I draw a figure by using the code shown below.

ax = df.plot(kind='bar', stacked=True,figsize=(13,10))
plt.title('Title List', fontsize=20) 
leg = ax.legend(loc='center right', bbox_to_anchor=(1.3, 0.5), ncol=1)
plt.tight_layout()
plt.savefig('images/image1.png', bbox_inches = "tight")  
plt.show()

When I run the code, some colors are the same.

How can I define unique colors in legend part?

Here is the screenshot enter image description here

S.N
  • 2,157
  • 3
  • 29
  • 78

1 Answers1

0

My answer:

After I defining colormap as rainbow, All defined colors in legend parts became unique.

Change to code

ax = df.plot(kind='bar', stacked=True,figsize=(13,10))

to

ax = df.plot(kind='bar', stacked=True,figsize=(13,10), colormap='rainbow')
S.N
  • 2,157
  • 3
  • 29
  • 78