programing

imshow의 수치가 너무 작습니다.

mailnote 2023. 8. 14. 23:03
반응형

imshow의 수치가 너무 작습니다.

Matlab의 imagesc()와 비슷하기 때문에 imshow()를 사용하여 numpy 배열을 시각화하려고 합니다.

imshow(random.rand(8, 90), interpolation='nearest')

회색 창의 중심에서 대부분의 공간이 비어 있는 상태에서 결과 수치는 매우 작습니다.수치를 크게 하려면 어떻게 파라미터를 설정해야 합니까?저는 figsize=(xx,xx)를 시도해 보았지만 제가 원하는 것이 아닙니다.감사합니다!

만약 당신이 주지 않는다면.aspect에 대한 주장.imshow다음 값을 사용합니다.image.aspect당신의matplotlibrc새 값의 기본값matplotlibrc이라equal.그렇게imshow동일한 가로 세로 비율로 배열을 표시합니다.

동일한 측면이 필요하지 않은 경우 설정할 수 있습니다.aspect로.auto

imshow(random.rand(8, 90), interpolation='nearest', aspect='auto')

다음과 같은 수치를 제공합니다.

imshow-auto

동일한 가로 세로 비율을 원한다면 사용자가 원하는 가로 세로 비율을 조정해야 합니다.figsize양상에 따라

fig, ax = subplots(figsize=(18, 2))
ax.imshow(random.rand(8, 90), interpolation='nearest')
tight_layout()

다음과 같은 이점이 있습니다.

imshow-equal

이상하네요, 저한테는 확실히 효과가 있어요.

from matplotlib import pyplot as plt

plt.figure(figsize = (20,2))
plt.imshow(random.rand(8, 90), interpolation='nearest')

저는 "MacOSX" 백엔드인 btw를 사용하고 있습니다.

2020년 업데이트

@baxxx에서 요청한 대로, 다음과 같은 이유로 업데이트가 있습니다.random.rand이 동안에는 더 이상 사용되지 않습니다.

이는 매트 플롯 슬립 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')

이 그림:

enter image description here

난수를 변경하려면 다음과 같이 실험할 수 있습니다.np.random.normal(0,1,(8,90))(여기서 평균은 = 0, 표준 편차 = 1).

저도 파이썬은 처음입니다.여기 당신이 원하는 것을 할 것처럼 보이는 것이 있습니다.

axes([0.08, 0.08, 0.94-0.08, 0.94-0.08]) #[left, bottom, width, height]
axis('scaled')`

저는 이것이 캔버스의 크기를 결정한다고 생각합니다.

언급URL : https://stackoverflow.com/questions/10540929/figure-of-imshow-is-too-small

반응형