ID_DI
DI's study notes
ID_DI
전체 방문자
오늘
어제
  • 분류 전체보기 (85)
    • Deep-Learning (3)
      • CNN (2)
      • NLP (1)
    • Data_Python (6)
      • Numpy (0)
      • Matplotlib (4)
    • Python (8)
      • Python Algorithm (6)
    • Java (36)
      • Java(base) (33)
      • Java practice(base) (2)
    • Git (12)
    • Algorithm (7)
    • etc (7)
    • linux (1)
    • DeskSetup (0)
    • TIL_모각코 (4)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • java.lang
  • java base
  • git add.
  • Github
  • matplotlib
  • 커밋
  • java
  • string to int
  • 정렬
  • 자바
  • Python
  • java.net
  • 파이썬
  • binarySearch
  • java 기초
  • 알고리즘
  • git
  • README.md
  • 합병정렬
  • staged

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ID_DI

DI's study notes

[Matplotlib] Plot (line) 그래프 / plt.plot(), plt.axis(), plt.title(), plt.xlabel(), plt.ylabel(), plt.legend(), plt.xticks(), plt.yticks()
Data_Python/Matplotlib

[Matplotlib] Plot (line) 그래프 / plt.plot(), plt.axis(), plt.title(), plt.xlabel(), plt.ylabel(), plt.legend(), plt.xticks(), plt.yticks()

2022. 4. 14. 22:33
Study_Matplotlib_plot

matplotlib¶

matplotlib.pyplot 라이브러리 import

In [1]:
import matplotlib.pyplot as plt

plot¶

plt.plot()¶

  • 기본 그래프 그리기
In [2]:
plt.plot([1,2,10], [10,20,5])#x,y 값 (1,10) (2,20) (10, 5)
plt.show()
In [3]:
plt.plot(['a', 'b', 'c'], [10, 29 ,5])
plt.show
Out[3]:
<function matplotlib.pyplot.show(close=None, block=None)>

axis()¶

  • 축의 범위 지정
In [4]:
plt.axis([-0.5, 2.2, 0, 21]) #[xmin, xmax, ymin, ymax]
plt.plot(['z', 'b', 'a'],[3,10,11])
plt.show()

title()¶

  • 제목 지정

xlabel()¶

  • x의 label 지정

ylabel()¶

  • y의 label 지정

lengend()¶

  • 범례표시
In [6]:
def make_chart_simple_line_chart():
    years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]
    gdp = [300.2, 543.3, 1075.3, 2862.5, 5979.6, 10289.7, 14958.3]
    
    plt.plot(years, gdp,marker='o', color = 'blue', linestyle = 'solid', label = 'label')
    
    #add title
    plt.title("Nominal GDP")
    
    #add label to the y-axis
    plt.ylabel("Billions of $")
    plt.xlabel("years")
    
    #범례표시
    plt.legend()
    
    plt.show()
    
make_chart_simple_line_chart()

여러개의 plot 그래프 그리기¶

In [7]:
plt.plot([1,2,3,4,5], [10,20,30,40,50])
plt.plot([2,3,4,5,6], [30,30,20,10,90])
Out[7]:
[<matplotlib.lines.Line2D at 0x1891135f6a0>]
In [8]:
import numpy as np

t = np.arange(0., 5., 0.2)

#빨간 대쉬, 파란 사각형, 녹색 삼각형
plt.plot(t,t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()

xticks()¶

  • x의 축의 label 을 붙임

yticks()¶

  • y의 축의 label 을 붙임
In [9]:
plt.plot([1,2,3,4,5], [10,20,30,40,50])
plt.plot([2,3,4,5,6], [30,30,20,10,90])

plt.xticks([0,1,2,3,4], labels=['one', 'two', 'three', 'four', 'five'])
plt.show()

'Data_Python > Matplotlib' 카테고리의 다른 글

[Matplotlib] pie 그래프와 예제 plt.pie()  (0) 2022.04.14
[Matplotlib] Scatter 그래프와 예제 plt.scatter  (0) 2022.04.14
[Matplotlib] Bar 그래프와 예제 plt.bar()  (0) 2022.04.14
    'Data_Python/Matplotlib' 카테고리의 다른 글
    • [Matplotlib] pie 그래프와 예제 plt.pie()
    • [Matplotlib] Scatter 그래프와 예제 plt.scatter
    • [Matplotlib] Bar 그래프와 예제 plt.bar()
    ID_DI
    ID_DI
    Computer Vision

    티스토리툴바