Together we managed to solve a similar problem. We use numeric values for your y-axis ticks, and then map them to desired strings with plt.xticks().
import matplotlib.pyplot as plt
from collections import OrderedDict
import re
T_OLD = {'10' : 'need1', '11':'need8', '12':'need11', '13':'need1','14':'need3'}
T_SRT = OrderedDict(sorted(T_OLD.items(), key=lambda t: t[0]))
x_val = list(map(int, T_SRT.keys()))
y_val = list(map(lambda x: int(re.findall(r'\d+', x)[-1]), T_SRT.values()))
plt.plot(x_val, y_val,'r')
plt.ylim([0.9*min(y_val),1.1*max(y_val)])
ax = plt.gca()
y_axis = list(set(y_val))
ax.set_yticks(y_axis)
ax.set_yticklabels(['need' + str(i) for i in y_axis])
plt.title('T_OLD')
plt.xlabel('time')
plt.ylabel('need')
plt.show()
But how to change this program, If instead of 'needs' there were their names, for example:
T_OLD = {'10': 'run', '11': 'tea', '12': 'mathematics', '13': 'run', '14', :'chemistry'}.
What code would a program have?
The result should look like the picture below.