欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python繪制K線圖之可視化神器pyecharts的使用

 更新時間:2021年03月02日 09:37:24   作者:王小王-123  
這篇文章主要介紹了Python繪制K線圖之可視化神器pyecharts的使用,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

K線圖

概念

股市及期貨市bai場中的K線圖的du畫法包含四個zhi數(shù)據(jù),即開盤dao價、最高價、最低價zhuan、收盤價,所有的shuk線都是圍繞這四個數(shù)據(jù)展開,反映大勢的狀況和價格信息。如果把每日的K線圖放在一張紙上,就能得到日K線圖,同樣也可畫出周K線圖、月K線圖。研究金融的小伙伴肯定比較熟悉這個,那么我們看起來比較復(fù)雜的K線圖,又是這樣畫出來的,本文我們將一起探索K線圖的魅力與神奇之處吧!

K線圖

用處

K線圖用處于股票分析,作為數(shù)據(jù)分析,以后的進入大數(shù)據(jù)肯定是一個趨勢和熱潮,K線圖的專業(yè)知識,說實話肯定比較的復(fù)雜,這里就不做過多的展示了,有興趣的小伙伴去問問百度小哥哥喲!

K線圖系列模板

最簡單的K線圖繪制

第一個K線圖繪制,來看看需要哪些參數(shù)吧,數(shù)據(jù)集都有四個必要的喲!

import pyecharts.options as opts
from pyecharts.charts import Candlestick
 
x_data = ["2017-10-24", "2017-10-25", "2017-10-26", "2017-10-27"]
y_data = [[20, 30, 10, 35], [40, 35, 30, 55], [33, 38, 33, 40], [40, 40, 32, 42]]
 
(
 Candlestick(init_opts=opts.InitOpts(width="1200px", height="600px"))
 .add_xaxis(xaxis_data=x_data)
 .add_yaxis(series_name="", y_axis=y_data)
 .set_series_opts()
 .set_global_opts(
  yaxis_opts=opts.AxisOpts(
   splitline_opts=opts.SplitLineOpts(
    is_show=True, linestyle_opts=opts.LineStyleOpts(width=1)
   )
  )
 )
 .render("簡單K線圖.html")
)

K線圖鼠標(biāo)縮放

大量的數(shù)據(jù)集的時候,我們不可以全部同時展示,我們可以縮放來進行定向展示。

from pyecharts import options as opts
from pyecharts.charts import Kline
 
data = [
 [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],
]
 
 
c = (
 Kline()
 .add_xaxis(["2017/7/{}".format(i + 1) for i in range(31)])
 .add_yaxis(
  "kline",
  data,
  itemstyle_opts=opts.ItemStyleOpts(
   color="#ec0000",
   color0="#00da3c",
   border_color="#8A0000",
   border_color0="#008F28",
  ),
 )
 .set_global_opts(
  xaxis_opts=opts.AxisOpts(is_scale=True),
  yaxis_opts=opts.AxisOpts(
   is_scale=True,
   splitarea_opts=opts.SplitAreaOpts(
    is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
   ),
  ),
  datazoom_opts=[opts.DataZoomOpts(type_="inside")],
  title_opts=opts.TitleOpts(title="Kline-ItemStyle"),
 )
 .render("K線圖鼠標(biāo)縮放.html")
)

有刻度標(biāo)簽的K線圖

我們知道一個數(shù)據(jù)節(jié)點,但是我們不能在圖像里面一眼看出有哪些數(shù)據(jù)量超出了它的范圍,刻度標(biāo)簽就可以派上用場了。

from pyecharts import options as opts
from pyecharts.charts import Kline
 
data = [
 [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],
]
 
c = (
 Kline()
 .add_xaxis(["2017/7/{}".format(i + 1) for i in range(31)])
 .add_yaxis(
  "kline",
  data,
  markline_opts=opts.MarkLineOpts(
   data=[opts.MarkLineItem(type_="max", value_dim="close")]
  ),
 )
 .set_global_opts(
  xaxis_opts=opts.AxisOpts(is_scale=True),
  yaxis_opts=opts.AxisOpts(
   is_scale=True,
   splitarea_opts=opts.SplitAreaOpts(
    is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
   ),
  ),
  title_opts=opts.TitleOpts(title="標(biāo)題"),
 )
 .render("刻度標(biāo)簽.html")
)

K線圖鼠標(biāo)無縮放

前面的是一個有縮放功能的圖例代碼,但是有時候我們不想要那么修改一下參數(shù)就可以了。

from pyecharts import options as opts
from pyecharts.charts import Kline
 
data = [
 [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],
]
 
 
c = (
 Kline()
 .add_xaxis(["2017/7/{}".format(i + 1) for i in range(31)])
 .add_yaxis("kline", data)
 .set_global_opts(
  yaxis_opts=opts.AxisOpts(is_scale=True),
  xaxis_opts=opts.AxisOpts(is_scale=True),
  title_opts=opts.TitleOpts(title="Kline-基本示例"),
 )
 .render("鼠標(biāo)無縮放.html")
)

大量數(shù)據(jù)K線圖繪制(X軸鼠標(biāo)可移動)

雖然有時候縮放可以容納較多的數(shù)據(jù)量,但是還是不夠智能,可以利用這個

from pyecharts import options as opts
from pyecharts.charts import Kline
 
data = [
 [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],
]
 
c = (
 Kline()
 .add_xaxis(["2017/7/{}".format(i + 1) for i in range(31)])
 .add_yaxis("kline", data)
 .set_global_opts(
  xaxis_opts=opts.AxisOpts(is_scale=True),
  yaxis_opts=opts.AxisOpts(
   is_scale=True,
   splitarea_opts=opts.SplitAreaOpts(
    is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
   ),
  ),
  datazoom_opts=[opts.DataZoomOpts(pos_bottom="-2%")],
  title_opts=opts.TitleOpts(title="Kline-DataZoom-slider-Position"),
 )
 .render("大量數(shù)據(jù)展示.html")
)

K線圖的繪制需要有專業(yè)的基本知識喲,不然可能有點惱火了。

到此這篇關(guān)于Python繪制K線圖之可視化神器pyecharts的使用的文章就介紹到這了,更多相關(guān)Python繪制K線圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python學(xué)習(xí)筆記之線程

    Python學(xué)習(xí)筆記之線程

    這篇文章主要介紹了Python線程詳解,本文詳細講解了線程方方面面的知識,如線程基礎(chǔ)知識線程狀態(tài)、線程同步(鎖)、線程通信(條件變量)等內(nèi)容,需要的朋友可以參考下
    2021-11-11
  • Python字符串和其常用函數(shù)合集

    Python字符串和其常用函數(shù)合集

    這篇文章主要給大介紹Python字符串和分享其常用函數(shù)合集,字符串、首字母大寫定義、所有字母大寫、所有字母小寫等函數(shù),具有一定的參考價值,需要的朋友可以參考一下
    2022-03-03
  • Python中裝飾器和魔法方法的區(qū)別解析

    Python中裝飾器和魔法方法的區(qū)別解析

    在Python中,裝飾器(Decorators)和魔法方法(Magic Methods)是兩種不同的高級特性,分別服務(wù)于不同的目的,這篇文章主要介紹了Python中裝飾器和魔法方法的區(qū)別,需要的朋友可以參考下
    2024-03-03
  • 詳解Numpy擴充矩陣維度(np.expand_dims, np.newaxis)和刪除維度(np.squeeze)的方法

    詳解Numpy擴充矩陣維度(np.expand_dims, np.newaxis)和刪除維度(np.squeeze)的方

    這篇文章主要介紹了詳解Numpy擴充矩陣維度(np.expand_dims, np.newaxis)和刪除維度(np.squeeze)的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • Python數(shù)據(jù)存儲之XML文檔和字典的互轉(zhuǎn)

    Python數(shù)據(jù)存儲之XML文檔和字典的互轉(zhuǎn)

    這篇文章主要介紹了Python數(shù)據(jù)存儲之XML文檔和字典的互轉(zhuǎn),通過如何將一個字典轉(zhuǎn)換為XML文檔,并將該XML文檔保存為文本文件的提問展開主題相關(guān)介紹,需要的朋友可以參考一下下面文章內(nèi)容
    2022-06-06
  • python多進程實現(xiàn)文件下載傳輸功能

    python多進程實現(xiàn)文件下載傳輸功能

    這篇文章主要為大家詳細介紹了python多進程實現(xiàn)文件下載傳輸功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • TensorFlow2.0矩陣與向量的加減乘實例

    TensorFlow2.0矩陣與向量的加減乘實例

    今天小編就為大家分享一篇TensorFlow2.0矩陣與向量的加減乘實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • python pyg2plot的原理知識點總結(jié)

    python pyg2plot的原理知識點總結(jié)

    在本篇文章里小編給大家整理的是一篇關(guān)于python pyg2plot的原理知識點總結(jié)內(nèi)容,有興趣的朋友們可以參考下。
    2021-02-02
  • 通過python獲取甲流分布數(shù)據(jù)

    通過python獲取甲流分布數(shù)據(jù)

    近期,多地學(xué)校出現(xiàn)因甲流導(dǎo)致的班級停課,兒科甲流患者就診量呈數(shù)倍增長,今天我們同樣的操作來獲取下現(xiàn)在甲流感染的數(shù)據(jù),需要的朋友可以參考下
    2023-03-03
  • Python3 字典dictionary入門基礎(chǔ)附實例

    Python3 字典dictionary入門基礎(chǔ)附實例

    Python字典是另一種可變?nèi)萜髂P?,且可存儲任意類型對象,如字符串、?shù)字、元組等其他容器模型,字典由鍵和對應(yīng)值成對組成,字典也被稱作關(guān)聯(lián)數(shù)組或哈希表
    2020-02-02

最新評論