Last answered:

27 Feb 2023

Posted on:

25 Feb 2023

2

regarding Colors

Hi, 


I am getting an eorror while plotting different colors ("rgbwymc") 


plt.figure(figsize=(9,6))
plt.bar(x=df_cars["Brand"], height=df_cars["Cars Listings"],color ="rgbwymc")
plt.xticks(rotation = 45)
plt.show()


ValueError: Using a string of single character colors as a color sequence is not supported. The colors can be passed as an explicit list instead.


Kindly lookin to that and revert to me.


Thanks, 

Siva 

 


1 answers ( 0 marked as helpful)
Instructor
Posted on:

27 Feb 2023

4

Hi Packiarajan, 

thanks for reaching out! It seems that the functionality of using a single string as a color has been deprecated in some versions of matplotlib and is no longer supported, that's why you're getting the error. If you'd like to have individual colors for each bar, you can do the following:
1. Have a list of all the colors, using their full names
2. Pass that list for the color argument
Here is some example code:

colors = ["red","green","blue","white","yellow","magenta","cyan"]
plt.bar(x = df_used_cars["Brand"], #specify the x axis
        height = df_used_cars["Cars Listings"], #specify the y axis
        color = colors)

Let me know if this version works for you or if you have any further questions!

Best,
365 Eli

Submit an answer