matplotlib fivethirtyeight adding y tick labels

Solutions on MaxInterview for matplotlib fivethirtyeight adding y tick labels by the best coders in the world

showing results for - "matplotlib fivethirtyeight adding y tick labels"
Estelle
07 Mar 2017
1# Assume the rest of the code is written
2#We begin by adding y-tick labels in the center of the graph — 
3#both bar plots have the same y-tick labels.
4#Below, we add the labels using Axes.text()
5
6x_coords = {'Alcohol': 0.82, 'Sulphates': 0.77, 'pH': 0.91,
7            'Density': 0.80, 'Total Sulfur Dioxide': 0.59,
8            'Free Sulfur Dioxide': 0.6, 'Chlorides': 0.77,
9            'Residual Sugar': 0.67, 'Citric Acid': 0.76,
10            'Volatile Acidity': 0.67, 'Fixed Acidity': 0.71}
11y_coord = 9.8
1213for y_label, x_coord in x_coords.items():
14    ax.text(x_coord, y_coord, y_label)
15    y_coord -= 1
16
17#adds vertical lines
18
19#Axes.axvline() method
20ax.axvline(x=0.5, color = 'grey',alpha = 0.1,linewidth = 1, ymin = 0.1, ymax = 0.9)
21ax.axvline(x=1.45, color = 'grey',alpha = 0.1,linewidth = 1, ymin = 0.1, ymax = 0.9)
22
23#add horrizontal lines
24
25ax.axhline(-1, color='grey', linewidth=1, alpha=0.5,
26          xmin=0.01, xmax=0.32)
27ax.text(-0.7, -1.7, '-0.5'+ ' '*31 + '+0.5',
28        color='grey', alpha=0.5)
29plt.show()
similar questions