본문 바로가기
파이썬의 기본

ax.plot, linestyle, 그래프 선 유형 설정, python(파이썬), matplotlib

by 루껍 2024. 4. 4.
반응형

ax.plot을 사용해서 그래프를 그릴때, 나타낼 수 있는 그래프 선의 유형은 다음과 같다.

 

1. solid 

2. dotted

3. dashed

4. dashdot

 

기본적인 사용방법은 다음과 같다. (dotted를 예로 함)

 

ax.plot(x축 데이터,  y축 데이터,  linestyle = 'dotted')

 

 

import numpy as np
import matplotlib.pyplot as plt

### 데이터 정의 ###
x_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y_arr = [1, 4, 9, 16, 25, 25, 25, 64, 81, 100]

### 데이터 시각화 ###
fig, ax = plt.subplots(figsize = (20, 20), nrows = 2, ncols = 2)

############################################################################
ax[0, 0].plot(x_arr, y_arr, color = 'black', lw = 3, linestyle = 'solid')
ax[0, 1].plot(x_arr, y_arr, color = 'black', lw = 3, linestyle = 'dotted')
ax[1, 0].plot(x_arr, y_arr, color = 'black', lw = 3, linestyle = 'dashed')
ax[1, 1].plot(x_arr, y_arr, color = 'black', lw = 3, linestyle = 'dashdot')
############################################################################

ax[0, 0].set_title(r'$solid$', fontsize = 25)
ax[0, 1].set_title(r'$dotted$', fontsize = 25)
ax[1, 0].set_title(r'$dahsed$', fontsize = 25)
ax[1, 1].set_title(r'$dashdot$', fontsize = 25)

ax[0, 0].tick_params(axis = 'both', labelsize = 22)
ax[0, 1].tick_params(axis = 'both', labelsize = 22)
ax[1, 0].tick_params(axis = 'both', labelsize = 22)
ax[1, 1].tick_params(axis = 'both', labelsize = 22)

 

 

'solid', 'dotted', 'dashed', 'dashdot' 대신 간소화된 기호를 대신 입력하여 같은 기능을 구현할 수 있다.

 

1.   '-'     ('solid')

2.  ':'    ('dotted')

3.  '--'    ('dashed')

4.  '-.'    ('dashdot')

 

 

import numpy as np
import matplotlib.pyplot as plt

### 데이터 정의 ###
x_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y_arr = [1, 4, 9, 16, 25, 25, 25, 64, 81, 100]

### 데이터 시각화 ###
fig, ax = plt.subplots(figsize = (20, 20), nrows = 2, ncols = 2)

#######################################################################
ax[0, 0].plot(x_arr, y_arr, color = 'black', lw = 3, linestyle = '-')
ax[0, 1].plot(x_arr, y_arr, color = 'black', lw = 3, linestyle = ':')
ax[1, 0].plot(x_arr, y_arr, color = 'black', lw = 3, linestyle = '--')
ax[1, 1].plot(x_arr, y_arr, color = 'black', lw = 3, linestyle = '-.')
#######################################################################

ax[0, 0].set_title(r'$solid$', fontsize = 25)
ax[0, 1].set_title(r'$dotted$', fontsize = 25)
ax[1, 0].set_title(r'$dahsed$', fontsize = 25)
ax[1, 1].set_title(r'$dashdot$', fontsize = 25)

ax[0, 0].tick_params(axis = 'both', labelsize = 22)
ax[0, 1].tick_params(axis = 'both', labelsize = 22)
ax[1, 0].tick_params(axis = 'both', labelsize = 22)
ax[1, 1].tick_params(axis = 'both', labelsize = 22)
반응형

댓글