Matplotlib bar chart: independently adjust alpha values for specific bars

I’m using the color format in RGBA format, and the fourth value is the alpha value, so I’m making use of the list of alpha values you’ve created to create a color list. I’ve applied that to the bar chart.

alphas_o=([.9, .9, .9, .9, .9, .9, .9, .5, .5, .5])
alphas_c=([.9, .9, .9, .9, .9, .9, .5, .5, .5, .5])
rgba_colors = np.zeros((10,4))
rgba_colors[:,0] = 1.0
rgba_colors[:, 3] = alphas_o
rgba_colors1 = np.zeros((10,4))
rgba_colors1[:,2] = 1.0
rgba_colors1[:, 3] = alphas_c

rects1 = ax.bar(x - width/2, req, width, color=rgba_colors)
rects2 = ax.bar(x + width/2, completed, width, color=rgba_colors1)

ax.set_ylabel('Counts',fontsize=12 )
ax.set_xticks(x)
ax.set_xticklabels(Months, fontsize=12)

orange_patch = mpatches.Patch(color='r', label='Total Open Requests')
blue_patch = mpatches.Patch(color='b', label='Completed Requests')
ax.legend(handles=[orange_patch, blue_patch],  frameon=False, fontsize=12, bbox_to_anchor=(.9, .8))

enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top