Screen Link:
My Code:
style.use('fivethirtyeight')
fig, ax = plt.subplots(figsize=(9, 5))
ax.barh(white_corr.index, white_corr, left=2, height=0.5)
ax.barh(red_corr.index, red_corr, height=0.5, left=-0.1)
ax.grid(b=False)
ax.set_yticklabels([])
ax.set_xticklabels([])
x_coords = {'Alcohol': 0.82, 'Sulphates': 0.77, 'pH': 0.91,
'Density': 0.80, 'Total Sulfur Dioxide': 0.59,
'Free Sulfur Dioxide': 0.6, 'Chlorides': 0.77,
'Residual Sugar': 0.67, 'Citric Acid': 0.76,
'Volatile Acidity': 0.67, 'Fixed Acidity': 0.71}
y_coord = 9.8
for y_label, x_coord in x_coords.items():
ax.text(x_coord, y_coord, y_label)
y_coord -= 1
ax.axvline(0.5, c='grey', alpha=0.6, linewidth=1, ymin=0.1, ymax=0.9)
ax.axvline(1.45, c='grey', alpha=0.6, linewidth=1, ymin=0.1, ymax=0.9)
plt.show()
From the tutorial, the coordinate for the y-tick label is 9.8
, and it reduces by 1
for every y-tick label. This is understood.
To visually separate the labels from the bar plots, we added two vertical lines:
The ymax
coordinate of the vertical lines is 0.9
(based on the axvline
code) . This is confusing spatially.
I would have expected the ymax
to be closer to 9.8
, since the Alcohol
tick label has a y-coordinate of 9.8
.
Please, I need clarification on this.
Thank you.