파이썬[Python]: matplotlib - plot 함수

matplotlib 모듈 - pyplot 모듈 - plot 함수(function)


/// 설명

x에 대응하는 y를 선이나 마커로 표시합니다.

※ 형식
matplotlib.pyplot.plot(*args, scalex=True, scaley=True, data=None, **kwargs)

reference
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html

/// 예제 default x = [0 ~ (y'length - 1)]

1
2
3
4
5
6
7
8
import matplotlib.pyplot as plt
 
= [12345678910]
plt.plot(y)
plt.show()
 
# y'length = default x' length
 
cs

/// 출력


/// 예제 x, y

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import matplotlib.pyplot as plt
 
= [12345678910]
= [149162536496481100]
 
plt.plot(x, y, 'r+--')
plt.show()
 
# y'length == x' length
#
# plt.plot(x, y, 'r+--')
#                [fmt] = 'r      +       --'
#                         color  makers  line_styles
#                see: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
 
cs

/// 출력


/// 예제 x, y, linewidth, markersize

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import matplotlib.pyplot as plt
 
= [12345678910]
= [149162536496481100]
 
# plt.plot(x, y, 'r+--', linewidth=4, markersize=15)
plt.plot(x, y, color='red', marker='+', linestyle='dashed', linewidth=4, markersize=15)
plt.show()
 
# y'length == x' length
#
# plt.plot(x, y, 'r+--')
#                [fmt] = 'r      +       --'
#                         color  makers  line_styles
#                see: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
 
cs

/// 출력


/// 예제 Plotting labelled data

1
2
3
4
5
6
7
8
9
import matplotlib.pyplot as plt
 
# test_dict = {'x': range(10), 'y': range(10)}
test_dict = {'x'range(10)}
test_dict['y'= test_dict['x']
 
plt.plot('x''y', data=test_dict)
plt.show()
 
cs

/// 출력


/// 예제 Plotting multiple sets of data

1
2
3
4
5
6
7
8
9
10
11
12
13
import matplotlib.pyplot as plt
 
x1 = [12345678910]
y1 = [149162536496481100]
 
x2 = [12345678910]
y2 = [12345678910]
 
#plt.plot(x1, y1, 'r+--', x2, y2, 'b+--')
plt.plot(x1, y1, 'r+--')
plt.plot(x2, y2, 'b+--')
plt.show()
 
cs

/// 출력


/// 예제 with Numpy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import matplotlib.pyplot as plt
import numpy as np
 
= [123]
= np.array([[12], [34], [56]])
plt.plot(x, y)
plt.show()
 
# x = [1, 2, 3]
# y = np.array([[1, 2], [3, 4], [5, 6]])
# for col in range(y.shape[1]):
#     plt.plot(x, y[:, col])
# plt.show()
 
 
# line 1              line 2
# x = [1, 2, 3]       x = [1, 2, 3]
# y = [1, 3, 5]       y = [2, 4, 6]
 
 
cs

/// 출력


* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수