Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

matplotalib에서 로그 스케일로 값을 시각화하는 방법은 무엇입니까?

<시간/>

matplotlib에서 로그 스케일로 값을 시각화하려면 yscale('log')을 사용할 수 있습니다. .

단계

  • matplotlib 및 numpy를 가져옵니다.

  • Figure 크기를 설정하고 서브플롯 사이와 주변의 패딩을 조정합니다.

  • x 만들기 및 y numpy를 사용하는 데이터 포인트.

  • yscale('log') 사용 로그 스케일로 값을 시각화합니다.

  • 플롯 xy 플롯을 사용하는 데이터 포인트 방법.

  • 그림에 범례를 표시합니다.

  • 그림을 표시하려면 show()를 사용하세요. 방법.

예시

import numpy as np
from matplotlib import pyplot as plt

# Set the figure size
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

# x and y data points
x = np.linspace(1, 100, 1000)
y = np.log(x)

# logarithmic scale
plt.yscale('log')

# Plot the x and y data points
plt.plot(x, y, c="red", lw=3, linestyle="dashdot", label="y=log(x)")

# Place the legend
plt.legend()

# Display the plot
plt.show()

출력

다음 출력을 생성합니다 -

matplotalib에서 로그 스케일로 값을 시각화하는 방법은 무엇입니까?