user2761786
user2761786

Reputation: 271

Centering ticks on row of a heatmap

I have attempted to move my yticks on the heat map below to the centre of the row it corresponds to.

This has worked, except for the fact I now get the white space at the bottom of the graph. Is there a way to achieve the ticks in the middle without the white space?

Original image & code:

enter image description here

heatmap = plt.pcolor(df2.T, cmap=cmap,  vmax=1, vmin=0)
plt.yticks(range(len(df2.columns )+1), o, size=15)

New Image & Code

enter image description here

heatmap = plt.pcolor(df2.T, cmap=cmap,  vmax=1, vmin=0)
plt.yticks(np.arange(0.5, len(df2.columns)+1,1), df2.columns, size=15)

Attempts

I have tried using

plt.yticks(np.arange(0.5, len(df2.columns)+0.5,1), o, size=15

Note the change from +1 to +0.5 This however, halves my bottom row. See below:

enter image description here

Upvotes: 1

Views: 344

Answers (1)

HYRY
HYRY

Reputation: 97321

You can use ylim to set the yaxis range:

plt.ylim(0, df2.shape[1])

Upvotes: 2

Related Questions