Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Data Science Basics Charts and Tables Bar Charts

Stephen Cole
PLUS
Stephen Cole
Courses Plus Student 15,809 Points

UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.

When this error appears, here is the fix:

colors = [color['color'] for color in list(plt.rcParams['axes.prop_cycle'])]

Or, at the very least, it seems to fix the problem.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Thanks for posting the work-around! Tagging Kenneth Love to make note of this.

Stephen or Chris...can you help please?

Note: after I originally submitted this comment I was able to get the code to run by deleting the: "color=colors[group%len(price_groups)] as shown below:

for group in price_groups: # ax.bar(group, price_groups[group], color=colors[group%len(price_groups)]) ax.bar(group, price_groups[group])

I have substituted "axes.prop_cycle" as you mention above (code below), but am still getting an error:

Traceback (most recent call last): File "dsb_charts.py", line 77, in <module> create_bar_chart(price_groups, "price_in_groups.png") File "dsb_charts.py", line 62, in create_bar_chart ax.bar(group, price_groups[group], color=colors[group%len(price_groups)]) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\cycler.py", line 223, in ge titem raise ValueError("Can only use slices with Cycler.getitem")


line 77 is "create_bar_chart(price_groups, "price_in_groups.png") ":

def create_bar_chart(price_groups, exported_figure_filename): fig = plt.figure() ax = fig.add_subplot(1, 1, 1) plt.style.use('ggplot') colors=plt.rcParams['axes.prop_cycle']

for group in price_groups:
    ax.bar(group, price_groups[group], color=colors[group%len(price_groups)])

labels = ["$0-50", "$50-100", "$100-150", "$150-200", "$200-250", "$250+"]
ax.legend(labels)

ax.set_title('Amount of Ties at price points')
ax.set_xlabel('Tie Price ($)')
ax.set_xticklabels(labels, ha='left')
ax.set_xticks( range(1, len(price_groups)+1) )
ax.set_ylabel('Number of Ties')

plt.grid(True)
fig.savefig(exported_figure_filename)

price_groups = group_prices_by_range(price_in_float) create_bar_chart(price_groups, "price_in_groups.png")


Kat Chaung's original code:

def create_bar_chart(price_groups, exported_figure_filename): fig = plt.figure() ax = fig.add_subplot(1, 1, 1) plt.style.use('ggplot') colors=plt.rcParams['axes.color_cycle']

for group in price_groups:
    ax.bar(group, price_groups[group], color=colors[group%len(price_groups)])

labels = ["$0-50", "$50-100", "$100-150", "$150-200", "$200-250", "$250+"]
ax.legend(labels)

ax.set_title('Amount of Ties at price points')
ax.set_xlabel('Tie Price ($)')
ax.set_xticklabels(labels, ha='left')
ax.set_xticks( range(1, len(price_groups)+1) )
ax.set_ylabel('Number of Ties')

plt.grid(True)
fig.savefig(exported_figure_filename)

1 Answer

Not sure if your solution is the problem, but the price range colors doesn't match with the bar colors of the x-axis.

For example the range 0-50$ is supposed to be gray, but the bar on the x-axis is blue. The indexing is off it seems.