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

Matplotlib를 사용하여 플롯의 면색을 변경하는 방법은 무엇입니까?

<시간/>

matplotlib를 사용하여 플롯의 면 색상을 변경하려면 다음 단계를 수행할 수 있습니다. -

  • 그림 크기를 설정하고 서브플롯 사이 및 주변 여백을 조정합니다.
  • numpy를 사용하여 x 및 y 데이터 포인트를 생성합니다.
  • 그림과 서브플롯 세트를 생성합니다.
  • plot()을 사용하여 x 및 y 데이터 포인트를 플로팅합니다. color=yellow 및 linewidth=7인 메소드
  • set_facecolor()를 사용하여 축의 면색 설정 .
  • 그림을 표시하려면 show()를 사용하세요. 방법.

예시

from matplotlib import pyplot as plt
import numpy as np

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

# Create x and y data points
x = np.linspace(-10, 10, 100)
y = np.sin(x)

# Create a figure and set of subplots
fig, ax = plt.subplots()

# Plot the x and y data points with color
ax.plot(x, y, color='yellow', lw=7)

# Set the facecolor
ax.set_facecolor('red')

plt.show()

출력

다음 출력을 생성합니다.

Matplotlib를 사용하여 플롯의 면색을 변경하는 방법은 무엇입니까? Matplotlib를 사용하여 플롯의 면색을 변경하는 방법은 무엇입니까?