pyechart1.6 双Y轴图

阿里云2000元红包!本站用户参与享受九折优惠!

以前使用pyechart0.5画的双Y轴图突然不能画出曲线了,甚是奇怪。在两台电脑重新安装0.5,还是不行。
于是改用最新版本pyechart 1.6

df_SKU = pd.read_csv('SKU&Rate2.csv',index_col=0)
df_final=df_SKU.tail(12)
v1 = list( df_final['SKU_number'].values)    
v2 =  list(df_final['inven_number'].values)            
v3 = list( df_final['rate'].values*100)
v1 = [int(each) for each in v1]
v2 = [int(each) for each in v2]
v3 = [int(each) for each in v3]
#x_data= list(str(df_final['YearMonth'].values) )
colors = ["#5793f3", "#d14a61", "#675bba"]
x_data = ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
import pyecharts.options as opts
from pyecharts.charts import Bar, Line
x_data = ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
bar = (
    Bar(init_opts=opts.InitOpts(width="800px", height="400px"))
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="SKU",
        yaxis_data= v1,
        label_opts=opts.LabelOpts(is_show=False),
    )
    .add_yaxis(
        series_name="INV",
        yaxis_data= v2,
        label_opts=opts.LabelOpts(is_show=False),
    )
    .extend_axis(
        yaxis=opts.AxisOpts(
            name="占比",
            type_="value",
            min_=0,
            max_=100,
            interval=15,
            axislabel_opts=opts.LabelOpts(formatter="{value} %"),
        )
    )
    .set_global_opts(
        tooltip_opts=opts.TooltipOpts(
            is_show=True, trigger="axis", axis_pointer_type="cross"
        ),
        xaxis_opts=opts.AxisOpts(
            type_="category",
            axispointer_opts=opts.AxisPointerOpts(is_show=True, type_="shadow"),
        ),
        yaxis_opts=opts.AxisOpts(
            name="SKU",
            type_="value",
            min_=0,
            max_=13000,
            interval=2000,
            axislabel_opts=opts.LabelOpts(formatter="{value} 单位"),
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
    )
)
line = (
    Line()
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="Rate",
        yaxis_index=1,
        y_axis=v3,
        label_opts=opts.LabelOpts(is_show=False),
    )
)
bar.overlap(line).render("SKU_mixed_bar_and_line.html") #保存为网页
bar.overlap(line).render_notebook()#在notbook直接显示


1574837628(1).png

切换主题,增加标记

import pyecharts.options as opts
from pyecharts.charts import Bar, Line
from pyecharts.globals import ThemeType
import pyecharts
print(pyecharts.__version__)
v1 = list( df_final['SKU_number'].values)    
v2 =  list(df_final['inven_number'].values)            
v3 = list( df_final['rate'].values*100)
attr = list( df_final['YearMonth'])
v1 = [int(each) for each in v1]
v2 = [int(each) for each in v2]
v3 = [int(each) for each in v3]
x_data= [str(each) for each in attr]
bar = (
    Bar(init_opts=opts.InitOpts(width="800px", height="400px",theme=ThemeType.DARK))
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="SKU",
        yaxis_data= v1,
        label_opts=opts.LabelOpts(is_show=False),
        
        markpoint_opts=opts.MarkPointOpts(
            data=[
                opts.MarkPointItem(type_="max", name="最大值"),
                opts.MarkPointItem(type_="min", name="最小值"),
            ]
        ),
    )
    .add_yaxis(
        series_name="INV",
        yaxis_data= v2,
        label_opts=opts.LabelOpts(is_show=False),
    )
    .extend_axis(
        yaxis=opts.AxisOpts(
            name="占比",
            type_="value",
            min_=0,
            max_=100,
            interval=15,
            axislabel_opts=opts.LabelOpts(formatter="{value} %"),
        )
    )
    .set_global_opts(
        tooltip_opts=opts.TooltipOpts(
            is_show=True, trigger="axis", axis_pointer_type="cross"
        ),
        xaxis_opts=opts.AxisOpts(
            type_="category",
            axispointer_opts=opts.AxisPointerOpts(is_show=True, type_="shadow"),
        ),
        yaxis_opts=opts.AxisOpts(
            name="SKU",
            type_="value",
            min_=0,
            max_=13000,
            interval=2000,
            axislabel_opts=opts.LabelOpts(formatter="{value} 单位"),
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
    )
)
line = (
    Line()
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="Rate",
        yaxis_index=1,
        y_axis=v3,
        label_opts=opts.LabelOpts(is_show=False),
    )
)
bar.overlap(line).render("SKU_mixed_bar_and_line.html")
bar.overlap(line).render_notebook()#render("mixed_bar_and_line.html")


主题.png

仪表盘

from pyecharts import options as opts
from pyecharts.charts import Gauge, Page
def gauge_base() -> Gauge:
    c = (
        Gauge()
        .add("", [("SKU/INV", 86.6%)])
        .set_global_opts(title_opts=opts.TitleOpts(title="Gauge-SKU"))
    )
    return c
gauge_base().render_notebook()


SKU_YI.png

1.6 和0.5版本安装

GitHub – pyecharts/pyecharts: 🎨 Python Echarts Plotting Library https://github.com/pyecharts/pyecharts/

https://www.jianshu.com/p/d7e4c23f3a6a

「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
Keras
0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论