Answers for "matplotlib FiveThirtyEight adding y-tick labels"

0

matplotlib FiveThirtyEight adding y-tick labels

# Assume the rest of the code is written
#We begin by adding y-tick labels in the center of the graph — 
#both bar plots have the same y-tick labels.
#Below, we add the labels using Axes.text()

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

#adds vertical lines

#Axes.axvline() method
ax.axvline(x=0.5, color = 'grey',alpha = 0.1,linewidth = 1, ymin = 0.1, ymax = 0.9)
ax.axvline(x=1.45, color = 'grey',alpha = 0.1,linewidth = 1, ymin = 0.1, ymax = 0.9)

#add horrizontal lines

ax.axhline(-1, color='grey', linewidth=1, alpha=0.5,
          xmin=0.01, xmax=0.32)
ax.text(-0.7, -1.7, '-0.5'+ ' '*31 + '+0.5',
        color='grey', alpha=0.5)
plt.show()
Posted by: Guest on August-23-2021

Code answers related to "matplotlib FiveThirtyEight adding y-tick labels"

Python Answers by Framework

Browse Popular Code Answers by Language