How to decrease height of y axis in plt.imshow
Question:
I am plotting an array in matplotlib using imshow. Here is my array:
df = pd.DataFrame({'x':[1,2,2,3,3,3],'y':[1,1,2,1,2,3],'z':[3,2,4,5,1,6]})
X = df.to_numpy()
I am plotting with this:
plt.imshow(X)
How can I edit the plot so that the height of the rows are narrower? Basically, I want to reduce the vertical dimension of each square so that the height of a square is 10% the width of each square.
I have been trying to use:
plt.figure(figsize=(w,h)
But manipulating both w and h values just makes the plot bigger or smaller, keeping the same scale.
As an example of how to height of each square should be less than the width, see this below:
Answers:
Instead of using imshow()
, use pcolor
to be able to scale the axis size.
plt.pcolor(X)
Then you can apply the fisize
parameter to change the aspect or to be even more strict about your plot size apply this technique.
I am plotting an array in matplotlib using imshow. Here is my array:
df = pd.DataFrame({'x':[1,2,2,3,3,3],'y':[1,1,2,1,2,3],'z':[3,2,4,5,1,6]})
X = df.to_numpy()
I am plotting with this:
plt.imshow(X)
How can I edit the plot so that the height of the rows are narrower? Basically, I want to reduce the vertical dimension of each square so that the height of a square is 10% the width of each square.
I have been trying to use:
plt.figure(figsize=(w,h)
But manipulating both w and h values just makes the plot bigger or smaller, keeping the same scale.
As an example of how to height of each square should be less than the width, see this below:
Instead of using imshow()
, use pcolor
to be able to scale the axis size.
plt.pcolor(X)
Then you can apply the fisize
parameter to change the aspect or to be even more strict about your plot size apply this technique.