广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Pyecharts中的饼图位置调整方式
  • 820
分享到

Pyecharts中的饼图位置调整方式

2024-04-02 19:04:59 820人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

目录Pyecharts饼图位置调整不调整可能会显示成这样调整后的效果是这样利用Pyecharts 制作饼图Pyecharts饼图位置调整 如果要把 pyecharts 里的饼图嵌入其

Pyecharts饼图位置调整

如果要把 pyecharts 里的饼图嵌入其他页面,有的时候需要调整饼图的位置。

不调整可能会显示成这样

调整后的效果是这样

关键代码在于:

center=["40%", "60%"]
def pie_base_proc(p_dict, p_list) -> Pie:
    c = (
        Pie(init_opts=opts.InitOpts(width=p_dict['width'],height=p_dict['height']))
        .add("", p_list,center=["40%", "60%"])
 
        .set_global_opts(title_opts=opts.TitleOpts(title=p_dict['title']),
                             legend_opts=opts.LegendOpts(orient=p_dict['orient'], pos_left=p_dict['pos_left'], pos_top=p_dict['pos_top']))
 
        .set_series_opts(label_opts=opts.LabelOpts(fORMatter="{b}", position='inside'))
 
    )
    return c
 
 
def lx_data_Pie(m_dict):
    p_dict = {'title':m_dict['title'], 'width':'300px', 'height': '300px'}
    # horizontal vertical
    p_dict['orient'] ="horizontal"
    p_dict['pos_left'] = "0%"
    p_dict['pos_top'] = "5%"
    m_data = m_dict['m_data']
    p_list = [list(z) for z in zip(m_data[0], m_data[1])]
    return pie_base_proc(p_dict,p_list)

利用Pyecharts 制作饼图

from pyecharts import options as opts
from pyecharts.charts import Pie
from random import randint

def pie_base() -> Pie:
    c = (
        Pie()
        .add("", [list(z) for z in zip(['宝马','法拉利','奔驰','奥迪','大众','丰田','特斯拉'],
                                       [randint(1, 20) for _ in range(7)])])
        .set_global_opts(title_opts=opts.TitleOpts(title="Pie-基本示例"))
        .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
    )
    return c

pie_base().render('G:/pythonWorkSpace/MatplotlibNumpypandas/pie_pyecharts.html')

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: Pyecharts中的饼图位置调整方式

本文链接: https://www.lsjlt.com/news/120874.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作