weixin_40686234
weixin_40686234
2021-05-21 22:43
采纳率: 100%
浏览 107

pyecharts两个散点图类型相同长度不同的x轴合并为一张散点图

pyecharts两个散点图类型相同长度不同的x轴合并为一张散点图

编程小白鼠还希望高人可以在代码上帮我调整。我会非常感谢。

1.最后图上展示效果 c_x轴对应c_y的数据,cc_x轴对应cc_y的数据

2.就像图上展示的那样 一个时间坐标对应一个标注点

 

from pyecharts import options as opts
from pyecharts.charts import Scatter

time_x =['2020-09-03 01:00:00', '2020-09-03 12:00:00', '2020-09-10 01:00:00', '2020-09-13 03:00:00', '2020-09-21 09:00:00', '2020-09-22 07:00:00', '2020-09-24 22:00:00']
# 共享x轴
c_x = ['2020-09-03 01:00:00',  '2020-09-13 03:00:00', '2020-09-21 09:00:00', '2020-09-22 07:00:00', ]
c_y = [[10],  [30], [36], [70], ]
cc_x = ['2020-09-03 12:00:00', '2020-09-10 01:00:00', '2020-09-24 22:00:00']
cc_y = [[66], [79], [90], ]

c = (
    Scatter(init_opts=opts.InitOpts(height='870px',width='860px'))
    .add_xaxis(c_x)
    .add_yaxis(
        "商家A",
            # c_y,
        [list(z) for z in zip(c_y, c_x)],
    )
    .set_global_opts()
)#=========================
cc = (
    Scatter()
    .add_xaxis(cc_x)
    .add_yaxis(
        "商家b",
        [list(z) for z in zip(cc_y, cc_x)],
    )
)
c.overlap(cc)
c.render("hebing_sandiantu.html")
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • technologist_18
    CSDN专家-Yang 2021-05-22 16:43
    已采纳

    数据长度需要和x轴长度一致

    from pyecharts import options as opts
    from pyecharts.charts import Scatter
    import numpy as np
    time_x =['2020-09-03 01:00:00', '2020-09-03 12:00:00', '2020-09-10 01:00:00', '2020-09-13 03:00:00', '2020-09-21 09:00:00', '2020-09-22 07:00:00', '2020-09-24 22:00:00']
    c = (
        Scatter(init_opts=opts.InitOpts(height='870px',width='860px'))
        .add_xaxis(time_x)
        .add_yaxis(
            "商家A",
            [10,  np.nan,np.nan,30, 36, 70,np.nan ],
        )
        .add_yaxis(
            "商家b",
           [np.nan,66, 79, np.nan,np.nan,np.nan,90 ],
        ))
    c.render("hebing_sandiantu.html")
    
    点赞 1 评论
  • technologist_18
    CSDN专家-Yang 2021-05-22 08:00

    那是碰到什么问题了呢

    点赞 评论
  • QA_Assistant
    有问必答小助手 2021-05-25 14:06

    您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

    如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

    ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

    点赞 评论

相关推荐