ํ์ด์ฌ์์ 3D ๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐ
์ฝ๋
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.plot([0, 0, 0], [0, 2, 4], [0, 5, 0], '')
plt.show()
- ์ A (x1, y1, z1)์ ์ขํ ์์ ์ฐ์ ๋ ax.plot([x1], [y1], [z1])์ด ๋๋ค.
- ๊ฐ์ ์๋ฆฌ๋ก ์ 2๊ฐ๋ฅผ ์ฐ์ผ๋ฉด ์ง์ ์ด, 3๊ฐ๋ฅผ ์ฐ์ผ๋ฉด ๊บพ์์ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ฆด ์ ์๋ค.
- ์ 3๊ฐ๋ฅผ ์ฐ์ผ๋ฉด ์๋์ ๊ฐ๋ค.
ax.plot([x1, x2, x3], [y1, y2, y3], [z1, z2, z3], '์์, ์ ์ํํ๋ฑ ์์ฑ ์ถ๊ฐ')
๊ฒฐ๊ณผ
์ฝ๋
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.plot([0, 0, 0], [0, 2, 4], [0, 5, 0], '')
ax.plot([1, 1, 1], [0, 2, 4], [0, 5, 0], '')
ax.plot([-1, -1, -1], [0, 2, 4], [0, 5, 0], '')
plt.show()
- plot์ 3๊ฐ๋ฅผ ๋๋ฉด ๊ทธ๋ํ 3๊ฐ๋ฅผ ๊ทธ๋ฆด ์ ์๋ค.
- ๊ฐ๊ฐ x์ขํ๋ง ๋ค๋ฅธ ๊ฐ์ ํํ์ ๊ทธ๋ํ๋ค.
๊ฒฐ๊ณผ
ํฌ๋กค๋งํ์ฌ DB์ ์ ์ฅํ ๋ฐ์ดํฐ๋ก ๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐ
์ฝ๋
import matplotlib.pyplot as plt
from day14.stockdao import StockDao
sd = StockDao()
samsung = sd.select("์ผ์ฑ์ ์")
sk = sd.select("SK")
lg = sd.select("LG")
samPriceList = []
lgPriceList = []
skPriceList = []
x1 = []
x2 = []
x3 = []
y1 = []
y2 = []
y3 = []
for idx, i in enumerate(samsung):
firstPrice = samsung[0].get('price')
price = i.get('price')
gap = price - firstPrice
percent = gap/firstPrice*100
samPriceList.append(percent)
x1.append(0)
y1.append(idx)
for idx, i in enumerate(lg):
firstPrice = lg[0].get('price')
price = i.get('price')
gap = price - firstPrice
percent = gap/firstPrice*100
lgPriceList.append(percent)
x2.append(1)
y2.append(idx)
for idx, i in enumerate(sk):
firstPrice = sk[0].get('price')
price = i.get('price')
gap = price - firstPrice
percent = gap/firstPrice*100
skPriceList.append(percent)
x3.append(2)
y3.append(idx)
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
ax.plot(x1, y1, samPriceList,'r')
ax.plot(x2, y2, lgPriceList,'g')
ax.plot(x3, y3, skPriceList,'b')
plt.show()
- ๊ฐ ๋ฐ์ดํฐ๋ฅผ ๋ด์ ๋ฆฌ์คํธ์์ ๊ธ์ก๋ง ํ๋์ฉ ๊บผ๋ด์ ๋ฆฌ์คํธ์ ๋ด๋๋ค.
for idx, i in enumerate(samsung):
firstPrice = samsung[0].get('price')
price = i.get('price')
gap = price - firstPrice
percent = gap/firstPrice*100
samPriceList.append(percent)
x1.append(0)
y1.append(idx)
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
plt.show()
๊ฒฐ๊ณผ
- ๋ณ๋ํ ๊ฐ๊ฒฉ์ ๋น์จ๋ก ๋ํ๋๊ธฐ ๋๋ฌธ์ ๋์ ๋๋ ทํ๊ฒ ๋ณํ๊ฐ ๋ณด์ธ๋ค.
- ๊ฐ๊ฒฉ์ ๋น์จ์ด ์๋๋ผ ๊ฐ๊ฒฉ ๊ทธ ์์ฒด๋ฅผ ๋น๊ตํ๋ค๋ฉด ํ ๊ทธ๋ํ ์์์ ๋ณํํ๋ ํญ์ด ๋ฏธ๋ฏธํ๊ฒ ๋ณด์ธ๋ค