-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_test.py
More file actions
145 lines (85 loc) · 2.5 KB
/
plot_test.py
File metadata and controls
145 lines (85 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 6 09:07:16 2025
@author: Admin
"""
import matplotlib.pyplot as plt
plt.plot([10, 20, 30, 40])
plt.show()
plt.title('plotting')
plt.plot([1,2,3,4],[12,43,25,15])
plt.show()
plt.title("Legend")
plt.plot([10, 20, 30, 40], label='asc')
plt.plot([12,43,25,15],label='desc')
plt.legend()
plt.show()
# 색상: color="알려진 색상
plt.title("color")
plt.plot([10,20,30,40],color='skyblue',label='skyblue')
plt.plot([40,30,20,10],color='pink',label='pink')
plt.legend()
plt.show()
# 선 형태: ls = "" / linestyle =
plt.title("linestyle")
plt.plot([10,20,30,40], color='r', linestyle ='--', label='dashed')
plt.plot([40,30,20,10],color='g',ls=':',label='dotted')
plt.legend()
plt.show()
# 선 대신 , 모양으로
plt.plot([10,20,30,40],'r-',label='circle')
plt.plot([40,30,20,10],'g^',label='triangle up')
plt.legend()
plt.show()
#그래프 기본 구조 생성 : matplotlib.pyplot.figure()
plt.figure()
# 그래프 기본 구조에 그래프를 그려주기
# 그래프 출력 : matplotlib.pyplot.show()
plt.show()
### Numpy를 이용하여 Dummy 데이터 생성 후, sin() 을 이용하여 시각화
import numpy as np
# Numpy의 범위 ; Numpy.arange(시작, 끝, 사이간격)
t = np.arange(0,10, 0.01)
y = np.sin(t)
## 시각화
# figsize=(10,6) 10:6 비율로 준비
plt.figure(figsize=(10,6))
plt.plot(t,y,lw=3,label='sin') # lw : 선 두께
plt.plot(t, np.cos(t),'r',label='cos') # 'r': 선 모양
plt.grid() # grid 추가
plt.legend()
plt.xlabel('time')
plt.ylabel('Amplitude')
plt.title('Sample Graph')
plt.xlim(0,np.pi) # x tick 값 변경
plt.ylim(-1.2, 1.2) # y tick 값 변경
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()
# 색상, 선 스타일 변경 두번째 방법
t=[0,1,2,4,5,8,9]
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=20)
plt.show()
#### 산점도 그래프
t = np.array([0,1,2,3,4,5,6,7,8,9])
y = np.array([9,8,7,9,8,3,2,4,3,4])
plt.figure(figsize=(10,6))
plt.scatter(t,y , marker='>')
plt.show()
colormap= t
plt.figure(figsize=(10,6))
plt.scatter(t,y , marker='>',
s = 50,
c = colormap)
plt.colorbar()
plt.show()