파이썬[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
※ 형식
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 y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 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 x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] 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 x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] # 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 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y1 = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] x2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] #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 x = [1, 2, 3] y = np.array([[1, 2], [3, 4], [5, 6]]) 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)
– 당신을 응원합니다. –
댓글
댓글 쓰기