(Package) matplotlib

์ž„๊ฒฝ๋ฏผยท2023๋…„ 10์›” 7์ผ
1
post-thumbnail

๐Ÿ”‘Summarization


  • Python package - Matplotlib Basic

๐Ÿ“—Contents


Module Load

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
rc('font', family='Arial Unicode MS')

Figure Basic

plt.figure(figsize=(10,6))
plt.plot()

plt.figure(figsize=(10,6))
plt.plot([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 1, 2, 3, 4, 2, 3, 5, -1, 3])
plt.plot()

๊ทธ๋ž˜ํ”„ ๊ธฐ์ดˆ


์‚ผ๊ฐํ•จ์ˆ˜ ๊ทธ๋ฆฌ๊ธฐ

x = np.arange(0, 12, 0.01)
y = np.sin(x)

plt.figure(figsize = (10, 6))
plt.plot(x, y, label = 'sin')
plt.plot(x, np.cos(x), label = 'cos')
plt.grid(True) # ๊ทธ๋ฆฌ๋“œ ์ƒ์„ฑ
plt.title('Example of sinewave') # ๊ทธ๋ฆผ ์ œ๋ชฉ
plt.xlabel('Time')
plt.ylabel('Amlitude')
plt.legend(loc = 'upper right') # ๋ฒ”๋ก€
plt.show()

๊ทธ๋ž˜ํ”„ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•

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

plt. figure(figsize=(10,6))
plt.plot(t, t, 'r--')
plt.plot(t, t ** 2, 'bs')
plt.plot(t, t   ** 3, 'g')
plt.show()

def drawGraph():
    t = list(range(0, 7))
    y = [1, 4, 5, 8, 9, 5, 3]
    plt.figure(figsize = (10, 6))
    plt.plot(t, y, color = 'green', linestyle = 'dashed', marker = 'o', markerfacecolor = 'blue', markersize = 15)
    plt.xlim([-0.5, 6.5])
    plt.ylim([0.5, 9.5])
    plt.show()
drawGraph()

ScatterPlot

def drawGraphScatter():
    t = np.array(range(0, 10))
    y = np.array([9, 8, 7, 9, 8, 3, 2, 4, 3, 4])

    plt.figure(figsize=(10,6))
    plt.scatter(t, y)
    plt.show()

drawGraphScatter()

t = np.array(range(0, 10))
colormap = t

def drawGraph():
    plt.figure(figsize=(20,6))
    plt.scatter(t, y, s = 100, c = colormap, marker = ">")
    plt.colorbar()
    plt.show()

drawGraph()

0๊ฐœ์˜ ๋Œ“๊ธ€