worenga
worenga

Reputation: 5856

White pcolor introduces white bar

I have the following script

import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(24,7)
heatmap = plt.pcolor(data)
plt.show()

Which results into this image

enter image description here

How can I remove the white bar at the very top?

Upvotes: 0

Views: 104

Answers (3)

Sahil M
Sahil M

Reputation: 1847

I am assuming here that your matrix is not a jagged matrix:

import matplotlib.pyplot as plt
import numpy as np

data = np.random.rand(24,7)
nrow, ncol = data.shape
heatmap = plt.pcolor(data)
# put the major ticks
heatmap.axes.set_xticks(np.arange(ncol), minor=False)
heatmap.axes.set_yticks(np.arange(nrow), minor=False)
heatmap.axes.set_xlim(0,ncol) # Assuming a non jagged matrix
heatmap.axes.set_ylim(0,nrow)
plt.show()

enter image description here

Upvotes: 3

Sakib Ahammed
Sakib Ahammed

Reputation: 2480

Just simple change. np.random.rand(24,7) replace to np.random.rand(25,7)

import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(25,7)
heatmap = plt.pcolor(data)
plt.show()

Output: enter image description here

Or add axis Like plt.axis([0,7,0,24])

import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(24,7)
heatmap = plt.pcolor(data)
plt.axis([0,7,0,24])
plt.show()

Output: enter image description here

Upvotes: 1

Amy Teegarden
Amy Teegarden

Reputation: 3972

You have to manually set the x and y limits sometimes when you're using pcolor.

import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(24,7)
heatmap = plt.pcolor(data)
plt.ylim(0, 24)
plt.show()

Upvotes: 3

Related Questions