0

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)

Which gives me: enter image description here

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: enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
connor449
  • 1,549
  • 2
  • 18
  • 49

2 Answers2

1

One way to do this is to use aspect. If it is "auto" or "1", it will be in the ratio you are seeing it. Changing it to say 0.5, will make it wider.

df = pd.DataFrame({'x':[1,2,2,3,3,3],'y':[1,1,2,1,2,3],'z':[3,2,4,5,1,6]})
plt.imshow(df, aspect = 0.5)

will give you...

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Redox
  • 9,321
  • 5
  • 9
  • 26
0

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.

Jan Willem
  • 820
  • 1
  • 6
  • 24