How to display all label values in matplotlib
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Unforgiving Himalayas Looping
--
Chapters
00:00 How To Display All Label Values In Matplotlib
00:40 Accepted Answer Score 88
00:59 Answer 2 Score 0
01:31 Thank you
--
Full question
https://stackoverflow.com/questions/2613...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #graph #matplotlib #axislabels
#avk47
    Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Unforgiving Himalayas Looping
--
Chapters
00:00 How To Display All Label Values In Matplotlib
00:40 Accepted Answer Score 88
00:59 Answer 2 Score 0
01:31 Thank you
--
Full question
https://stackoverflow.com/questions/2613...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #graph #matplotlib #axislabels
#avk47
ACCEPTED ANSWER
Score 88
The issue here is that the number of ticks -set automatically - isn’t the same as the number of points in your plot.
To resolve this, set the number of ticks:
ax1.set_xticks(np.arange(len(x)))
Before the ax1.set_xticklabels(x) call.
ANSWER 2
Score 0
or better
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
from other answers in SO
from matplotlib import ticker
import numpy as np
labels = [
    "tench",
    "English springer",
    "cassette player",
    "chain saw",
    "church",
    "French horn",
    "garbage truck",
    "gas pump",
    "golf ball",
    "parachute",
]
fig = plt.figure()
ax = fig.add_subplot(111)
plt.title('Confusion Matrix', fontsize=18)
data = np.random.random((10,10))
ax.matshow(data, cmap=plt.cm.Blues, alpha=0.7)
ax.set_xticklabels([''] + labels,rotation=90)
ax.set_yticklabels([''] + labels)
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
for i in range(data.shape[0]):
    for j in range(data.shape[1]):
        ax.text(x=j, y=i,s=int(data[i, j]), va='center', ha='center', size='xx-small')
plt.xlabel('Predicted')
plt.ylabel('True')
plt.show()
