源碼
# encoding:utf-8
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
# 線性增長
date = np.linspace(1, 15, 15)
# 當天的收盤價格
endPrice = np.array([2511.90,2538.26,2510.68,2591.66,2732.98,2701.69,2701.29,2678.67,2726.50,2681.50,2739.17,2715.07,2823.58,2864.90,2919.08]
)
# 當天的開盤價格
beginPrice = np.array([2438.71,2500.88,2534.95,2512.52,2594.04,2743.26,2697.47,2695.24,2678.23,2722.13,2674.93,2744.13,2717.46,2832.73,2877.40])
# print(date) # 打印日期
plt.figure()
for i in range(0,15):
# 通過循環遍歷數據畫出柱狀圖
# x座標
dateOne = np.zeros([2])
dateOne[0] = i
dateOne[1] = i
# print(dateOne)
# y座標
priceOne = np.zeros([2])
priceOne[0] = beginPrice[i]
priceOne[1] = endPrice[i]
if endPrice[i] > beginPrice[i]:
# 如果收盤價格大於開盤價格說明股票上漲 用紅色表示 lw爲線條粗細
plt.plot(dateOne, priceOne,'r',lw=8)
else:
# 如果收盤價格小於開盤價格說明股票下跌 用綠色表示 lw爲線條粗細
plt.plot(dateOne, priceOne,'g',lw=5)
plt.show()
效果