def test_kline_user_define_markline_style(): kline = Kline("K 线图-自定义标记点风格") kline.add("日K", DATE, data, mark_point=["min", "max"], mark_point_symbolsize=80, datazoom_orient='vertical', mark_line_valuedim=['lowest', 'highest']) kline.show_config() kline.render()
def test_kline(): # kline_0 v1 = [[2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03], [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07], [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82], [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78], [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22]] kline = Kline("K 线图示例") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1) kline.show_config() kline.render() # kline_1 kline = Kline("K 线图示例") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1, mark_point=["max"], is_datazoom_show=True) kline.show_config() kline.render()
def view(code, start_, end_): ''' 使用pyecharts展示数据 :param code: 股票代码 :param start_: 开始时间(包含)格式为'2018-01-01' :param end_: 结束时间(包含)格式为'2018-01-01' :return: ''' # 从数据库获取数据 th = get_data_from_db(code, start_, end_) ''' 官网网址:http://pyecharts.org/#/zh-cn/charts?id=klinecandlestick%ef%bc%88k%e7%ba%bf%e5%9b%be%ef%bc%89 Kline.add() 方法签名 add(name, x_axis, y_axis, **kwargs) name -> str 图例名称 x_axis -> list x 坐标轴数据 y_axis -> [list], 包含列表的列表 y 坐标轴数据。数据中,每一行是一个『数据项』,每一列属于一个『维度』。 数据项具体为 [open, close, lowest, highest] (即:[开盘值, 收盘值, 最低值, 最高值]) ''' # 此处存放的是K线数组 v1 = th.values.tolist() # 存放X轴横坐标数组,此处选用的是日期 v2 = [str(x.strftime('%Y-%m-%d')) for x in th.index] kline = Kline("{0} K线图".format(code)) ''' is_datazoom_show:是否显示放大缩小 mark_point:标记最大最小值 ''' kline.add("日K", v2, v1, is_datazoom_show=True, mark_point=["min", "max"]) # 打印配置信息 kline.show_config() try: kline.render('股票[{0}]K线图.html'.format(code)) except Exception as e: print('生成图形出错啦[{0}]'.format(e))
def test_kline(): # kline_0 v1 = [[2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03], [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07], [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82], [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78], [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22]] kline = Kline("K 线图示例") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1) kline.show_config() kline.render() # kline_1 kline = Kline("K 线图示例") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1, mark_point=["max"], is_datazoom_show=True) kline.show_config() kline.render() # kline_2 kline = Kline("K 线图示例") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1, mark_point=["max"], is_datazoom_show=True, datazoom_orient='vertical') kline.show_config() kline.render()
#-*-coding:utf-8 from pyecharts import Kline import pandas_datareader.data as web import datetime df_stockload = web.DataReader("000001.SS", "yahoo", datetime.datetime(2018, 1, 1), datetime.datetime(2019, 1, 1)) kline = Kline("行情显示图") # 数据转换 ohlc = list( zip(df_stockload.Open, df_stockload.Close, df_stockload.Low, df_stockload.High)) dates = df_stockload.index.strftime('%Y-%m-%d') kline.add("日K", dates, ohlc, is_datazoom_show=True, mark_line=["max"], mark_point=["max"], xaxis_rotate=30, yaxis_min=0.9 * min(df_stockload["Low"])) kline.show_config() kline.render(r'k.html')
def test_custom(): # custom_0 attr = ['A', 'B', 'C', 'D', 'E', 'F'] v1 = [10, 20, 30, 40, 50, 60] v2 = [15, 25, 35, 45, 55, 65] v3 = [38, 28, 58, 48, 78, 68] bar = Bar("Line - Bar 示例") bar.add("bar", attr, v1) line = Line() line.add("line", v2, v3) bar.custom(line.get_series()) bar.show_config() bar.render() # custom_1 v1 = [10, 20, 30, 40, 50, 60] v2 = [30, 30, 30, 30, 30, 30] v3 = [50, 50, 50, 50, 50, 50] v4 = [10, 10, 10, 10, 10, 10] es = EffectScatter("Scatter - EffectScatter 示例") es.add("es", v1, v2) scatter = Scatter() scatter.add("scatter", v1, v3) es.custom(scatter.get_series()) es_1 = EffectScatter() es_1.add("es_1", v1, v4, symbol='pin', effect_scale=5) es.custom(es_1.get_series()) es.show_config() es.render() # custom_2 import random v1 = [[2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03], [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07], [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82], [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78], [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22]] attr = ["2017/7/{}".format(i + 1) for i in range(31)] kline = Kline("Kline - Line 示例") kline.add("日K", attr, v1) line_1 = Line() line_1.add("line-1", attr, [random.randint(2400, 2500) for _ in range(31)]) line_2 = Line() line_2.add("line-2", attr, [random.randint(2400, 2500) for _ in range(31)]) kline.custom(line_1.get_series()) kline.custom(line_2.get_series()) kline.show_config() kline.render()