# How to add numbers to the axes of a graph?

I am trying to make a graph of k (as in k-means) vs error, and I can't get it to show the actual number of k on the x-axis (1-15, not just the even numbers), nor any any numbers at all if I add a title to X.

I have looked at the data frame documentation and the matplotlib axes documentation, and I couldn't find anything telling me how to get it to show the numbers? Even if I have to manually specify them?

rdf.plot.line(title='Number of clusters Vs mean accuracy')


rdf.plot.line(title='Number of clusters Vs mean accuracy',
x='parameters',
y='mean_validation_score')


I don't understand how to get the x axis to show all 15 numbers (1-15).

• Are the values of $k$ in your DataFrame? – Adrian Keister Sep 12 '18 at 15:49
• They are, in the form of a column of dicts: 0 {'n_clusters': 1} 1 {'n_clusters': 2} 2 {'n_clusters': 3} etc. – Chor Hatara Hud'u Keturi Sep 12 '18 at 15:53
• I would collapse that column into a purely numeric column, so that you can set it as the x= part of your plot command. – Adrian Keister Sep 12 '18 at 15:56
• Thanks @AdrianKeister , turns out that was (most of) the answer I used in the end. I extracted a list of the numbers and added them as the xtick parameter. – Chor Hatara Hud'u Keturi Sep 12 '18 at 20:25
• You're quite welcome! – Adrian Keister Sep 12 '18 at 20:27

Use xticks. e.g.
x=np.arange(1,16)