Matplotlib에서 선 두께를 조정하는 방법


다음 구문을 사용하는 linewidth 인수 함수를 사용하여 Matplotlib 플롯에서 선 두께를 쉽게 조정할 수 있습니다.

matplotlib.pyplot.plot(x, y, 선폭=1.5)

기본적으로 선 너비는 1.5이지만 0보다 큰 값으로 조정할 수 있습니다.

이 튜토리얼에서는 이 기능의 실제 사용에 대한 몇 가지 예를 제공합니다.

예 1: 선 두께 조정

다음 코드는 간단한 선 차트를 만들고 선 너비를 3으로 설정하는 방법을 보여줍니다.

 import matplotlib. pyplot as plt
import numpy as np

#define x and y values
x = np. linspace (0, 10, 100)
y1 = np. sin (x)*np. exp (-x/3)

#create line plot with line width set to 3
plt. plot (x, y1, linewidth= 3 )

#displayplot
plt. show ()

matplotlib에서 선 너비 조정

예 2: 여러 선의 두께 조정

다음 코드는 여러 선의 두께를 한 번에 조정하는 방법을 보여줍니다.

 import matplotlib. pyplot as plt
import numpy as np

#define x and y values
x = np. linspace (0, 10, 100)
y1 = np. sin (x)*np. exp (-x/3)
y2 = np. cos (x)*np. exp (-x/5)

#create line plot with multiple lines
plt. plot (x, y1, linewidth= 3 )
plt. plot (x, y2, linewidth= 1 )

#displayplot
plt. show () 

Python의 matplotlib에서 여러 선 가중치 조정

예 3: 캡션의 선 두께 조정

다음 코드는 두께가 다른 여러 선을 만들고 이에 따라 각 선의 두께를 표시하는 범례를 만드는 방법을 보여줍니다.

 import matplotlib. pyplot as plt
import numpy as np

#define x and y values
x = np. linspace (0, 10, 100)
y1 = np. sin (x)*np. exp (-x/3)
y2 = np. cos (x)*np. exp (-x/5)

#create line plot with multiple lines
plt. plot (x,y1,linewidth=3,label=' y1 ')
plt. plot (x, y2, linewidth=1, label=' y2 ')

#add legend
plt. legend ()

#displayplot
plt. show () 

matplotlib 범례의 선 너비 조정

추가 리소스

Matplotlib에서 줄 사이의 영역을 채우는 방법
Matplotlib 플롯에서 진드기를 제거하는 방법
Matplotlib 플롯 외부에 범례를 배치하는 방법

의견을 추가하다

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다