강의노트 그래프 그리기

조회수 89 • 댓글 0 • 수정 5개월 전 크게 보기  
  • Matplotlib
  • matplotlib

matplotlib

여기서 Figure는 다음과 같이 구성된다.

Figure

Matplotlib은 데이터를 Figure에 그래프로 표시하며, 각 Figure은 하나 이상의 Axes를 포함할 수 있다. Axes는 점들을 지정할 수 있는 영역이다. Axes가 포함된 Figure를 만드는 가장 간단한 방법은 pyplot.subplots를 사용하는 것입니다. 그리고 Axes.plot을 사용하여 데이터를 그릴 수 있다.

fig = plt.figure()  # an empty figure with no Axes
fig, ax = plt.subplots()  # a figure with a single Axes
fig, axs = plt.subplots(2, 2)  # a figure with a 2x2 grid of Axes
# a figure with one axes on the left, and two on the right:
fig, axs = plt.subplot_mosaic([['left', 'right_top'],
                               ['left', 'right_bottom']])

Axes

axes객체는 " ax = fig.subplots( ) "로 생성한다. figure위의 모든 객체는 ax를 통해서 만들고 보여줄 수 있다.

import matplotlib.pyplot as plt
import numpy as np

fig, axs = plt.subplots(ncols=2, nrows=2, figsize=(3.5, 2.5),
                        layout="constrained")
# for each Axes, add an artist, in this case a nice label in the middle...
for row in range(2):
    for col in range(2):
        axs[row, col].annotate(f'axs[{row}, {col}]', (0.5, 0.5),
                            transform=axs[row, col].transAxes,
                            ha='center', va='center', fontsize=18,
                            color='darkgrey')
fig.suptitle('plt.subplots()')
  • Axes를 Figure에 추가하는 방법
    • "Figure.add_axes" :
    • "pyplot.subplot" 혹은 "Figure.subplots" :
    • "pyplot.subplot_mosaic" 과 "Figure.subplot_mosaic" :
      fig, axs = plt.subplot_mosaic([['left', 'right'], ['bottom', 'bottom']])
      

Axis

이 객체들은 스케일, 범위와 틱스 이 객체는 눈금(축의 마크)과 눈금 레이블(눈금에 레이블을 지정하는 문자열)과 한계를 설정한다. 눈금의 위치는 Locator 개체에 의해 결정되고 눈금 레이블 문자열은 Formatter에 의해 지정된다.

Artist

기본적으로 그림에 보이는 모든 것은 Artist이다.(그림, 축, 축 객체도 포함). 여기에는 Text 객체, Line2D 객체, collection 객체, Patch 객체 등이 포함된다. 그림이 렌더링되면 모든 Artist는 캔버스에 그려진다. 대부분의 Artist는 Axes에 묶여 있어서 Artist는 여러 축에서 공유하거나 다른 축으로 이동할 수 없다.

첫 글입니다.
다음 글
댓글
댓글로 소통하세요.