figure of imshow() is too small
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Secret Catacombs
--
Chapters
00:00 Figure Of Imshow() Is Too Small
00:32 Answer 1 Score 87
00:47 Answer 2 Score 2
01:02 Accepted Answer Score 213
01:41 Answer 4 Score 11
02:12 Thank you
--
Full question
https://stackoverflow.com/questions/1054...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #numpy #matplotlib
#avk47
ACCEPTED ANSWER
Score 213
If you don't give an aspect argument to imshow, it will use the value for image.aspect in your matplotlibrc. The default for this value in a new matplotlibrc is equal.
So imshow will plot your array with equal aspect ratio.
If you don't need an equal aspect you can set aspect to auto
imshow(random.rand(8, 90), interpolation='nearest', aspect='auto')
which gives the following figure

If you want an equal aspect ratio you have to adapt your figsize according to the aspect
fig, ax = subplots(figsize=(18, 2))
ax.imshow(random.rand(8, 90), interpolation='nearest')
tight_layout()
which gives you:

ANSWER 2
Score 87
That's strange, it definitely works for me:
from matplotlib import pyplot as plt
plt.figure(figsize = (20,2))
plt.imshow(random.rand(8, 90), interpolation='nearest')
I am using the "MacOSX" backend, btw.
ANSWER 3
Score 11
Update 2020
as requested by @baxxx, here is an update because random.rand is deprecated meanwhile.
This works with matplotlip 3.2.1:
from matplotlib import pyplot as plt
import random
import numpy as np
random = np.random.random ([8,90])
plt.figure(figsize = (20,2))
plt.imshow(random, interpolation='nearest')
This plots:
To change the random number, you can experiment with np.random.normal(0,1,(8,90)) (here mean = 0, standard deviation = 1).
ANSWER 4
Score 2
I'm new to python too. Here is something that looks like will do what you want to
axes([0.08, 0.08, 0.94-0.08, 0.94-0.08]) #[left, bottom, width, height]
axis('scaled')`
I believe this decides the size of the canvas.
