Why does this Matplotlib map have an extra column?

The name of the question speaks for itself. Take a look at the figure generated by this code. Yes??

data = np.random.randn(20*15)
matrix = data.reshape((20,15))

xlabels = range(15)
ylabels = range(20)

fig, ax = plt.subplots(figsize=(13,10))
heatmap = ax.pcolor( matrix, cmap=mpl.cm.PiYG, vmax=max(data), vmin=min(data))

plt.xticks(xlabels)
plt.yticks(ylabels)
plt.colorbar(heatmap)

      

enter image description here

+3


source to share


1 answer


(reply to comment)

I suspect this is due to conversion errors int

- float

in the internals matplotlib

. That is matplotlib

, it considers the limits to x

be (0, 15.0 ... 01) and rounds them down to (0, 16) instead of keeping them at (0, 15). If you set it explicitly as



ax.set_xlim(0, 15)

      

or if you resize 15

to 20

in your array, there is no white column. It might be worth pointing out the error at matplotlib

.

+4


source







All Articles