0

I am trying to build a line plot with y-axis as text instead of numbers and I have tried this solution but the y-axis still have numbers instead of 'text'. What am I doing wrong. CurrentCoresLE is a list of strings.

Y_AXIS_VALUES = list(numpy.sort(list(set(CurrentCoresLE))))
Y_AXIS = [Y_AXIS_VALUES.index(CurrentCoresLE[i]) for i in range(len(CurrentCoresLE))]
one = axes4.plot(Y_AXIS, color = '0.2', label='CoresUsed')
axes4.set_ylabel('Cores')
#https://stackoverflow.com/questions/17074772/using-text-on-y-axis-in-matplotlib-instead-of-numbers
#plt.yticks(Y_AXIS, Y_AXIS_VALUES)
axes4.set_yticks(Y_AXIS, Y_AXIS_VALUES)
axes4.legend(prop={'size':6}, ncol=4)
axes4.xaxis.grid(True)

And when I try plt instead of axes4, it does give text but in only one spot here is an example:enter image description here Here is an exmaple Y_AXIS_VALUES and Y_AXIS

['0B2S', '0B3S', '0B4S', '1B3S', '2B0S', '2B2S']
[4, 4, 5, 5, 5, 3, 3, 3, 2, 1, 0, 1, 0, 1, 1, 0, 0, 1, 2, 1, 2, 2, 1, 0, 1, 2, 2, 1, 0, 1, 2, 1, 1, 2, 2, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 3, 3, 3, 2, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 1, 1]
5
  • Can you show your data. Then I can try to help you. This seems not too hard. Commented Apr 3, 2016 at 13:19
  • Need to see the values of Y_AXIS and Y_AXIS_VALUES. Commented Apr 3, 2016 at 13:21
  • For now, you can try to use plt.yticks(np.arange(min(Y_value), max(Y_value), len(Your_txt_list))) with ax.set_yticklables(Your_txt_list). I'm not sure this was correct. Commented Apr 3, 2016 at 13:24
  • @HanZhengzu: axes subplot does not use set_yticklables. it only has set_yticks. and set_yticks only accepts floating point values. Commented Apr 3, 2016 at 13:49
  • @Sung: I did give the values of Y_AXIS and Y_AXIS_VALUES Commented Apr 3, 2016 at 13:50

1 Answer 1

0

This is how I fixed it.

axes4 = fig.add_subplot(514)
Y_AXIS_VALUES = list(numpy.sort(list(set(CurrentCoresLE))))
Y_AXIS = [Y_AXIS_VALUES.index(CurrentCoresLE[i]) for i in range(len(CurrentCoresLE))]
one = axes4.plot(Y_AXIS, color = '0.2', label='CoresUsed')
axes4.set_ylabel('Cores')
ytickNames = axes4.set_yticklabels(Y_AXIS_VALUES)
fontnum = 10
plt.setp(ytickNames,  fontsize=fontnum)
axes4.legend(prop={'size':6}, ncol=4)
axes4.xaxis.grid(True)

I guess the trick was to set the yticktabels first and use setp

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.