Python pyecharts Line折線圖的具體實現
一、繪制折線圖
import seaborn as sns import numpy as np import pandas as pd import matplotlib as mpl import matplotlib.pyplot as plt %matplotlib inline plt.rcParams['font.sans-serif']=['Microsoft YaHei'] # 用來正常顯示中文標簽 plt.rcParams['axes.unicode_minus']=False # 用來正常顯示負號 from datetime import datetime plt.figure(figsize=(16,10)) import pyecharts.options as opts from pyecharts.charts import Line from pyecharts.faker import Faker from pyecharts.charts import Bar import os from pyecharts.options.global_options import ThemeType
# 讀入數據 cnbodfgbsort=pd.read_csv("cnbodfgbsort.csv")
得到的cnbodfgbsort
數據:
import pyecharts.options as opts from pyecharts.charts import Line from pyecharts.faker import Faker c = ( Line() .add_xaxis(cnbodfgbsort.TYPE.tolist()) #X軸 .add_yaxis("票價",cnbodfgbsort.PRICE.tolist()) #Y軸 .add_yaxis("人次",cnbodfgbsort.PERSONS.tolist()) #Y軸 .set_global_opts(title_opts=opts.TitleOpts(title="電影票價與人次")) #標題 ) c.render_notebook() # 顯示
二、添加最小值最大值平均值
import pyecharts.options as opts from pyecharts.charts import Line from pyecharts.faker import Faker c = ( Line() .add_xaxis(cnbodfgbsort.TYPE.tolist()) .add_yaxis("票價",cnbodfgbsort.PRICE.tolist()) .add_yaxis("人次",cnbodfgbsort.PERSONS.tolist(), markpoint_opts=opts.MarkPointOpts( data=[ opts.MarkPointItem(type_="max", name="最大值"), opts.MarkPointItem(type_="min", name="最小值"), ] ), markline_opts=opts.MarkLineOpts( data=[opts.MarkLineItem(type_="average", name="平均值")] ),) .set_global_opts(title_opts=opts.TitleOpts(title="電影票價與人次")) ) c.render_notebook()
三、豎線提示信息
tooltip_opts=opts.TooltipOpts(trigger="axis")
四、顯示工具欄
tooltip_opts=opts.TooltipOpts(trigger="axis")
五、實心面積填充
.set_series_opts( areastyle_opts=opts.AreaStyleOpts(opacity=0.5), # 透明度 label_opts=opts.LabelOpts(is_show=False), # 是否顯示標簽 )
六、是否跳過空值
import pyecharts.options as opts from pyecharts.charts import Line from pyecharts.faker import Faker y = Faker.values() y[3], y[5] = None, None c = ( Line() .add_xaxis(Faker.choose()) .add_yaxis("商傢A", y, is_connect_nones=True) .set_global_opts(title_opts=opts.TitleOpts(title="Line-連接空數據")) .render("line_connect_null.html") )
如下圖:y[3],y[5]數據都是空值,如果直接顯示的話,圖表會出錯
# 使用這個參數來跳過空值,避免折現斷掉 is_connect_nones=True
import pyecharts.options as opts from pyecharts.charts import Line from pyecharts.faker import Faker y = Faker.values() y[3], y[5] = None, None c = ( Line() .add_xaxis(Faker.choose()) .add_yaxis("商傢A", y, is_connect_nones=True) .set_global_opts(title_opts=opts.TitleOpts(title="Line-連接空數據")) ) c.render_notebook()
七、折線光滑化
is_smooth=True
八、多X軸
參考官網:》multiple_x_axes
九、階梯圖
is_step=True
到此這篇關於Python pyecharts Line折線圖的具體實現的文章就介紹到這瞭,更多相關Python pyecharts Line折線圖內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!
推薦閱讀:
- pyecharts實現數據可視化
- Python繪制散點圖之可視化神器pyecharts
- Python echarts實現數據可視化實例詳解
- pyecharts如何旋轉折線圖的X軸標簽
- Python繪制折線圖可視化神器pyecharts案例