본문 바로가기
Python/matplotlib

[matplotlib] line 및 marker 설정하기.

by ds31x 2023. 7. 21.

기본적으로 graph에서 사용되는 line 및 marker의 스타일 (유형, 굵기, 색, 마커)을 변경하는 것은

Axes에서 제공하는 다양한 graph를 그리는 모든 메서드들에서 필요하기 때문에 공통적인 parameters가 제공됨.

 

다음이 많이 사용되는 것들을 정리해 놓은 것임.

parameter desc. value
linestyle ls로도 쓰이며, 선의 종류. '-'  : solid(실선),
':' : dotted(점선),
'--' : dashed(파선),
'-.' : dashdot(파점선)
linewidth lw로도 쓰이며, 선의 굵기를 지정 float
color 선의 색 'w' : white
'r' : red
'g' : green
'b' : blue
'y' : yellow
'c'
: cyan
'm'
: magenta
alpha 투명도 float, [0.,1.],
1.인 경우 불투명,
0.인 경우 완전투명
markersize 마커 크기 float
markeredgewidth 마커의 외곽선 굵기 float
markerfacecolor 마커의 색 color 참고.
markeredgecolor 마커의 외곽선 색 color 참고.

 

 

marker parameter는 마커의 종류를 결정하며 다음의 값을 가짐.

  • + : cross
  • o : circle
  • * : star
  • . : dot
  • s : square
  • v : tirangle_down
  • ^ : triangle_up
  • < : tirangle_left
  • > : triangle_right
  • p : pentagon
  • h : hexagon
  • | : vline marker
  • _ : hline marker

위의 parameters 는 거의 모든 graph에서 공통적으로 사용된다.

  • key-value로 형태로 argument를 지정하는 걸 개인적으로 권하지만,
  • formatting string (fmt)으로 이들 값들을 조합하여 positional argument로 한번에 설정하는 경우도 많다.

주로 첫번째, 두번째 argument들은 graph를 그리는데 필수 데이터들에 해당하고,
이들 다음의 position에 fmt argument가 위치하는게 일반적이다.


다음의 예는 blue, circle, dashed line이 그려지게 된다.

plot[x, y, 'bo--']
728x90

'Python > matplotlib' 카테고리의 다른 글

[matplotlib] 3D Plot  (0) 2024.01.21
[matplotlib] x축과 y축을 그리기: spines  (0) 2023.08.08
[matplotlib] : backend 란  (0) 2023.07.20
[matplotlib]: Figure and Axes  (0) 2023.07.20
[Python] matplotlib : Axis Scale and Ticks  (0) 2023.07.14