0

I am Working on a large data set and trying to get some important information from the stacked bar chart but when I plotted it I noticed that colors of the label aren't unique and that is a big issue for me. My goal is to set a unique color for each label I did a lot of research before posting this question here for example. But they aren't working, it's giving error 'AxesSubplot' object has no attribute 'set_color_cycle'

# my dataset is big so I am providing its instance
#suppose I have data of few cites and their complaints 
city = ['NEW YORK', 'ASTORIA', 'BRONX', 'BRONX', 'ELMHURST', 'BROOKLYN',
       'NEW YORK', 'BRONX', 'KEW GARDENS', 'BROOKLYN']
complaints = ['Noise - Street/Sidewalk', 'Blocked Driveway', 'Blocked Driveway',
       'Illegal Parking', 'Illegal Parking', 'Illegal Parking',
       'Illegal Parking', 'Blocked Driveway', 'Illegal Parking',
       'Blocked Driveway']
# and from this I have created a stack bar chart
test2 = new_cutmr_df[['Complaint Type', 'City']]
cmpltnt_rela = test2.groupby(['City', 'Complaint Type']).size().unstack().fillna(0).plot(kind='bar', legend = True, stacked=True)
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5),ncol=2)
cmpltnt_rela.plot(figsize=(18,14))

whose graph looks something like this enter image description here

where you can notice color repetition in legend

Darkstar Dream
  • 1,649
  • 1
  • 12
  • 23
  • It would be better if you could provide 'test2' data – Farooq Sk Jan 22 '20 at 05:37
  • it's nothing it is just for creating dataframe type object where I added those columns well I added it in edit – Darkstar Dream Jan 22 '20 at 05:48
  • You even repeat your `set_color_cycle` error message, while your linked post clearly writes "In more recent versions of mplib (1.5+), the set_color_cycle function has been deprecated in favour of ax.set_prop_cycle(color=[...]).". You didn't try to understand Ernest's hint in the comments to your question? – JohanC Jan 22 '20 at 07:22
  • Did you at least try to replace `set_color_cyle` with `set_prop_cycle(color=...`? – JohanC Jan 22 '20 at 09:05
  • 2
    Does this answer your question? [How to set unique color for individual value of legend](https://stackoverflow.com/questions/59840519/how-to-set-unique-color-for-individual-value-of-legend) – Diziet Asahi Jan 22 '20 at 09:59
  • yes it solved thanks – Darkstar Dream Jan 23 '20 at 07:50

0 Answers0