Matplotlib aspect ratio for narrow matrices

I have a matrix 200x3in python that I would like to build. However, using Matplotlib, I get the following drawing. How can I build an image that looks better?

my code is:

import matplotlib.pyplot as plt
plt.imshow(spectrum_matrix)
plt.show()

enter image description here

+4
source share
1 answer

You can use set_aspect():

import matplotlib.pyplot as plt
import numpy as np

spectrum_matrix = np.random.rand(200,3)

plt.imshow(spectrum_matrix)
plt.axes().set_aspect('auto')
plt.show()

Output:

enter image description here

+1
source

Source: https://habr.com/ru/post/1606473/


All Articles