Issue with displaying labels in matplotlib

matplotlib

Solution

Have a look at the `matplotlib.pyplot.xticks` function, which sets or gets the x-axis tick locations and labels. If I call this

locs, labels = plt.xticks()

in your example code I get the the xticks are locatedat

>>> locs
[ -2.,   0.,   2.,   4.,   6.,   8.,  10.]

Noting that the two points -2 and 10 have empty labels, this corresponds to 5 x-axis tick locations, so you won't get all of your labels plotted since the number of x-axis tick labels exceeds the number of x-axis tick locations. Try replacing

ax.set_xticklabels(['']+HOST, rotation=90)

with

ax.xticks(range(len(HOST), HOST, rotation=90)

Here we are setting both the xtick locations and labels. Of course a similar replacement is required for the y-axis tick marks.

Problem

I am a new user in python and matplotlib so be gentle. I have a plot with changed x and y labels so they correspond to chemical compounds. However as make a 10x10 plot for instance (I think the limit is 8x8) not all of my labels are showing. Of course I want that changed so that all the labels are present in a 8 x 12 plot for instance. Below are the code that I am using so far just with random numbers. ``` import numpy as np import matplotlib.pyplot as plt HOST = ['RuO2', 'IrO2', 'TiO2', 'MnO2','SnO2','MoO2','NbO2','Dummy','Dummy','Dummy'] GUEST = ['Ru','Ir','Ti','Mn','Sn','Fe','Ni','Zn','Mg','D'] data = np.random.random((10,10)) fig = plt.figure() ax = fig.add_subplot(111) cax = ax.matshow(data) fig.colorbar(cax) ax.set_xticklabels(['']+HOST,rotation=90) ax.set_yticklabels(['']+GUEST) plt.show() ``` This will in time of course be modified to my data etc.

Original source