I wanted to see if I could make one of the columns stand out by making it wider than the others.
It actually worked. Used the gridspec object to create a layout with 6 columns instead of 5. The first chart takes up two columns on the grid and the others take up just one.
import matplotlib.gridspec as gridspec
def add_ax(grid_loc, title, color='#FF8C00', show_y_labels=False):
ax = fig.add_subplot(grid_loc, facecolor='#F2F5F7')
ax.tick_params(left=False, bottom=False, right=False, top=False)
ax.xaxis.set_ticks([])
ax.barh(data.characters.apply(lambda x: x.replace('_', ' ')), data[title], color=color)
ax.set_title(title.replace('_', ' '), fontsize=15)
ax.tick_params(axis='y', labelsize=12, labelleft=show_y_labels)
for _, spine in ax.spines.items():
spine.set_visible(False)
first_one = True
for i, val in data[title].iteritems():
if i == len(data) - 1:
first_one = False
ax.text(val + 1, i, str(round(val)) + '%', va='center')
else:
ax.text(val + 1, i, str(round(val)), va='center')
return ax
fig = plt.figure(figsize=(16, 6), facecolor='#F2F5F7')
grid = gridspec.GridSpec(ncols=6, nrows=14, figure=fig)
cols = data.columns.to_list()
add_ax(grid[:, :2], 'favorable', 'blue', True)
colors=['#85ceeb', 'darkgreen', 'darkgreen', 'darkgreen']
for x in range(2, 6):
add_ax(grid[:,x], cols[x], colors[x-2])
plt.suptitle("'Star Wars' Character Favorability Ratings", fontsize=20, x=0.22, y=1.06, fontweight='bold')
plt.text(-210, 15.9, 'By 834 Respondents', fontsize=16, fontweight='light')
plt.show()