반응형
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)
반응형
'파이썬의 기본' 카테고리의 다른 글
[파이썬] 배열(list)에서의 메소드(method)/내장함수 총정리 (10) | 2022.08.11 |
---|---|
[파이썬] 1차원 배열(list)의 슬라이싱(slicing) (12) | 2022.08.09 |
[파이썬] 1차원 배열(list)의 인덱싱 (0) | 2022.08.08 |
[파이썬] 1차원 배열(list)을 생성하는 다양한 방법 (0) | 2022.08.07 |
댓글