import pyecharts.options as opts from pyecharts.charts import Line from pyecharts.globals import ThemeType from pyecharts.faker import Faker datex = [1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009] datey = [0.32,0.32,0.32,0.32,0.33,0.33,0.34,0.37,0.37,0.37,0.37,0.39,0.41,0.42,0.44] ( Line(init_opts=opts.InitOpts(theme=ThemeType.DARK)) .set_global_opts( title_opts=opts.TitleOpts(title= " 美國郵費階梯圖",subtitle="課本例1"), # toolbox_opts = opts.ToolboxOpts(is_show=True), # legend_opts = opts.LegendOpts(is_show=True), yaxis_opts=opts.AxisOpts( min_=3, max_=4.5, type_="value", axistick_opts=opts.AxisTickOpts(is_show=True), splitline_opts=opts.SplitLineOpts(is_show=True), ), visualmap_opts = opts.VisualMapOpts(is_show=True) # "Price",datx, daty, is_tep = True,is_label_show = True,yaxis_min =0.3, # yaxis_max = 0.45 ) .add_xaxis(xaxis_data = datex) .add_yaxis( series_name = "Price", y_axis = list(datey), # y_axis = Faker.values(), # datey, is_step=True, symbol="emptyCircle", is_symbol_show=True, label_opts=opts.LabelOpts(is_show=True), # markline_opts=opts.MarkPointOpts( # data=[ # opts.MarkPointItem(type_="min",y=0.32), # opts.MarkPointItem(type_="max",y=0.44), # ] # ), # # 是否選中圖例 # is_selected = True, # # 是否連接空數據,空數據使用 `None` 填充 # is_connect_nones = True, # linestyle_opts = opts.LineStyleOpts( # is_show=True, # opacity=1, # ) ) .set_colors(['RED','BLACK']) .render_notebook() ) # Line()
以上圖為例
運行結果
錯誤原因:數據類型,(此處不涉及echarts 主題,Echart有自帶的主題,但是pyecharts如果要使用其他主題的畫,需要安裝echarts-themes-pypkg包。它提供了 vintage, macarons, infographic, shine 和 roma等主題。使用命令
pip install echarts-themes-pypkg
)
datex 雖然為list 數據,但是此處需要的是str
快速直接、簡單粗暴修改
同時 修改
你以為這就結束了?
?
?
?
?
?
???????
?
?
?
?
?
是的,就這么簡單