使用pyecharts如同使用前端echarts,这里主要介绍pyecharts的源码内的图表属性不满足使用,应该怎么办?

使用pyecharts生成柱状图
pyecharts开源链接:http://pyecharts.herokuapp.com/bar
根据官方样例:

# encoding: utf-8
from pyecharts import Bar, Pagepage = Page()attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]v1 = [5, 20, 36, 10, 75, 90]v2 = [10, 25, 8, 60, 20, 80]chart = Bar("柱状图-数据堆叠", **style.init_style)chart.add("商家A", attr, v1, is_stack=True)chart.add("商家B", attr, v2, is_stack=True, is_more_utils=True)page.add(chart)


在这里主要是对属性的介绍
比如说:

字段 用处
title 标题
title_pos 标题距离左侧位置(百分比/数字)
title_top 标题距离顶部位置(百分比/数字)
以上等等都是可以根据源码可以查看,一步步添加
源码bar.py:
# coding=utf-8from pyecharts.chart import Chartclass Bar(Chart):"""<<< 柱状图/条形图 >>>柱状/条形图,通过柱形的高度/条形的宽度来表现数据的大小。"""def __init__(self, title="", subtitle="", **kwargs):super(Bar, self).__init__(title, subtitle, **kwargs)def add(self, *args, **kwargs):self.__add(*args, **kwargs)return selfdef __add(self,name,x_axis,y_axis,is_stack=False,bar_category_gap="20%",**kwargs):""":param name:系列名称,用于 tooltip 的显示,legend 的图例筛选。:param x_axis:x 坐标轴数据。:param y_axis:y 坐标轴数据。:param is_stack:数据堆叠,同个类目轴上系列配置相同的 stack 值可以堆叠放置。默认为 False。:param kwargs:"""assert len(x_axis) == len(y_axis)kwargs.update(x_axis=x_axis)chart = self._get_all_options(**kwargs)if is_stack:is_stack = "stack_" + str(self._option["series_id"])else:is_stack = ""xaxis, yaxis = chart["xy_axis"]self._option.update(xAxis=xaxis, yAxis=yaxis)self._option.get("legend")[0].get("data").append(name)self._option.get("series").append({"type": "bar","name": name,"data": y_axis,"stack": is_stack,"barCategoryGap": bar_category_gap,"label": chart["label"],"markPoint": chart["mark_point"],"markLine": chart["mark_line"],"seriesId": self._option.get("series_id"),})self._config_components(**kwargs)

更多属性添加源码chart.py:

# coding=utf-8import randomimport pyecharts.constants as constants
from pyecharts.base import Base
from pyecharts.echarts.option import get_base_optionsclass Chart(Base):"""`Chart`类是所有非自定义类的基类,继承自 `Base` 类"""def __init__(self,title,subtitle,width=800,height=400,title_pos="auto",title_top="auto",title_color=None,subtitle_color=None,title_text_size=18,subtitle_text_size=12,background_color=None,page_title=constants.PAGE_TITLE,renderer=constants.CANVAS_RENDERER,extra_html_text_label=None,is_animation=True,):""":param title:主标题文本,支持 \n 换行,默认为 "":param subtitle:副标题文本,支持 \n 换行,默认为 "":param width:画布宽度,默认为 800(px):param height:画布高度,默认为 400(px):param title_pos:标题距离左侧距离,默认为'left',有'auto', 'left', 'right','center'可选,也可为百分比或整数:param title_top:标题距离顶部距离,默认为'top',有'top', 'middle', 'bottom'可选,也可为百分比或整数:param title_color:主标题文本颜色,默认为 '#000':param subtitle_color:副标题文本颜色,默认为 '#aaa':param title_text_size:主标题文本字体大小,默认为 18:param subtitle_text_size:副标题文本字体大小,默认为 12:param background_color:画布背景颜色,默认为 '#fff':param page_title:指定生成的 html 文件中 <title> 标签的值。默认为 'Echarts':param renderer:指定使用渲染方式,有 'svg' 和 'canvas' 可选,默认为 'canvas'。3D 图仅能使用 'canvas'。:param extra_html_text_label:额外的 HTML 文本标签,(<p> 标签)。类型为 list,list[0] 为文本内容,list[1] 为字体风格样式(选填)。如 ["this is a p label", "color:red"]:param is_animation:是否开启动画,默认为 True。V0.5.9+"""super(Chart, self).__init__(width=width,height=height,renderer=renderer,page_title=page_title,extra_html_text_label=extra_html_text_label,is_animation=is_animation,)def add(self,angle_data=None,angle_range=None,angleaxis_label_interval=None,area_color=None,area_opacity=None,axis_range=None,bar_category_gap=None,border_color=None,boundary_gap=None,center=None,calendar_date_range=None,calendar_cell_size=None,coordinate_region=None,datazoom_type=None,datazoom_range=None,datazoom_orient=None,datazoom_xaxis_index=None,datazoom_yaxis_index=None,datazoom_extra_type=None,datazoom_extra_range=None,datazoom_extra_orient=None,datazoom_extra_xaxis_index=None,datazoom_extra_yaxis_index=None,effect_brushtype=None,effect_period=None,effect_scale=None,extra_data=None,extra_name=None,funnel_gap=None,funnel_sort=None,geo_emphasis_color=None,geo_normal_color=None,geo_cities_coords=None,geo_effect_period=None,geo_effect_traillength=None,geo_effect_color=None,geo_effect_symbol=None,geo_effect_symbolsize=None,graph_layout=None,graph_gravity=None,graph_edge_length=None,graph_repulsion=None,graph_edge_symbol=None,graph_edge_symbolsize=None,grid_width=None,grid_height=None,grid_top=None,grid_bottom=None,grid_left=None,grid_right=None,grid3d_width=None,grid3d_height=None,grid3d_depth=None,grid3d_opacity=None,grid3d_shading=None,grid3d_rotate_speed=None,grid3d_rotate_sensitivity=None,is_angleaxis_show=None,is_area_show=None,is_axisline_show=None,is_calculable=None,is_calendar_heatmap=None,is_clockwise=None,is_convert=None,is_datazoom_show=None,is_datazoom_extra_show=None,is_fill=None,is_focusnode=None,is_geo_effect_show=None,is_grid3d_rotate=None,is_label_show=None,is_label_emphasis=None,is_legend_show=None,is_liquid_animation=None,is_liquid_outline_show=None,is_more_utils=None,is_map_symbol_show=None,is_piecewise=None,is_radiusaxis_show=None,is_random=None,is_roam=None,is_rotatelabel=None,is_smooth=None,is_splitline_show=None,is_stack=None,is_step=None,is_symbol_show=None,is_toolbox_show=None,is_visualmap=None,is_xaxislabel_align=None,is_yaxislabel_align=None,is_xaxis_inverse=None,is_yaxis_inverse=None,is_xaxis_boundarygap=None,is_yaxis_boundarygap=None,is_xaxis_show=None,is_yaxis_show=None,item_color=None,label_color=None,label_pos=None,label_text_color=None,label_text_size=None,label_formatter=None,label_emphasis_textcolor=None,label_emphasis_textsize=None,label_emphasis_pos=None,legend_orient=None,legend_pos=None,legend_top=None,legend_selectedmode=None,legend_text_size=None,legend_text_color=None,line_curve=None,line_opacity=None,line_type=None,line_width=None,line_color=None,liquid_color=None,maptype=None,mark_line=None,mark_line_raw=None,mark_line_symbolsize=None,mark_line_valuedim=None,mark_line_coords=None,mark_point=None,mark_point_raw=None,mark_point_symbol=None,mark_point_symbolsize=None,mark_point_textcolor=None,mark_point_valuedim=None,pieces=None,radius_data=None,radius=None,rosetype=None,rotate_step=None,scale_range=None,shape=None,start_angle=None,symbol_size=None,symbol=None,sankey_node_width=None,sankey_node_gap=None,type=None,tooltip_trigger=None,tooltip_trigger_on=None,tooltip_axispointer_type=None,tooltip_formatter=None,tooltip_text_color=None,tooltip_font_size=None,tooltip_background_color=None,tooltip_border_color=None,tooltip_border_width=None,tree_layout=None,tree_symbol=None,tree_symbol_size=None,tree_orient=None,tree_top=None,tree_left=None,tree_bottom=None,tree_right=None,tree_collapse_interval=None,tree_label_position=None,tree_label_vertical_align=None,tree_label_align=None,tree_label_text_size=None,tree_label_rotate=None,tree_leaves_position=None,tree_leaves_vertical_align=None,tree_leaves_align=None,tree_leaves_text_size=None,tree_leaves_rotate=None,treemap_left_depth=None,treemap_drilldown_icon=None,treemap_visible_min=None,visual_orient=None,visual_range_color=None,visual_range_size=None,visual_range_text=None,visual_range=None,visual_text_color=None,visual_pos=None,visual_top=None,visual_type=None,visual_split_number=None,visual_dimension=None,word_gap=None,word_size_range=None,x_axis=None,xaxis_margin=None,xaxis_interval=None,xaxis_force_interval=None,xaxis_pos=None,xaxis_name_gap=None,xaxis_name_size=None,xaxis_name_pos=None,xaxis_name=None,xaxis_rotate=None,xaxis_min=None,xaxis_max=None,xaxis_type=None,xaxis_label_textsize=None,xaxis_label_textcolor=None,xaxis_line_color=None,xaxis_line_width=None,xaxis3d_name=None,xaxis3d_name_size=None,xaxis3d_name_gap=None,xaxis3d_min=None,xaxis3d_max=None,xaxis3d_interval=None,xaxis3d_margin=None,yaxis_margin=None,yaxis_interval=None,yaxis_force_interval=None,yaxis_pos=None,yaxis_formatter=None,yaxis_rotate=None,yaxis_min=None,yaxis_max=None,yaxis_name_gap=None,yaxis_name_size=None,yaxis_name_pos=None,yaxis_type=None,yaxis_name=None,yaxis_label_textsize=None,yaxis_label_textcolor=None,yaxis_line_color=None,yaxis_line_width=None,yaxis3d_name=None,yaxis3d_name_size=None,yaxis3d_name_gap=None,yaxis3d_min=None,yaxis3d_max=None,yaxis3d_interval=None,yaxis3d_margin=None,zaxis3d_name=None,zaxis3d_name_size=None,zaxis3d_name_gap=None,zaxis3d_min=None,zaxis3d_max=None,zaxis3d_margin=None,**kwargs):"""`add()` 方法只是用于提供自动参数补全"""return self...等等

那么重点来了,我自己写一个样例,以上的属性还是没有办法满足我的需求,比如我要生成一个这样的柱状图:


根据属性我可以把y轴的线宽属性调成0,yaxis_line_width=0, 代码如下,效果如图:

bar.add("当前堆使用率", attr, head_used_percent, is_stack=True, legend_pos="80%", legend_top="5%", legend_orient="vertical", yaxis_name=u"当前堆百分比", yaxis_name_pos="end", xaxis_line_width=1, yaxis_line_width=0, xaxis_line_color="#9a9090")

很明显这个刻度印记去不掉,这个时候怎么办?
首先我们思考一个问题,pyecharts和前端echarts的关系,一个是后端的图表库,一个是前端的图表插件,那么有什么联系?
根据pyecharts的方法,可以将这个柱状图生成HTML文件,打开这个HTML文件你就会发现它其实就是前端echarts插件代码的应用,这就意味着前端echarts能够使用的属性,pyecharts基本都能使用。图里的是echarts的option属性,而pyecharts的bar._option就相当于echarts的option。
echarts的官方网址:https://echarts.baidu.com/examples/editor.html?c=bar-gradient

以上加入后两行代码就能达到想要的效果。

bar = Bar("", title_pos="10%")
bar.add("堆空闲百分比", attr, head_free_percent, is_stack=True,label_color=["#3aa1ff", "#4ecb73"])
bar.add("当前堆使用率", attr, head_used_percent, is_stack=True, legend_pos="80%", legend_top="5%",legend_orient="vertical", yaxis_name=u"当前堆百分比", yaxis_name_pos="end",xaxis_line_width=1, yaxis_line_width=0, xaxis_line_color="#9a9090")
bar._option.get("yAxis")[0]["axisTick"] = False
bar._option.get("yAxis")[0]["axisLine"] = {"show": False}

如果想要达到其他的echarts效果,都可以采用相同的方法。
例如:

bar._option.get("series")[0]["barGap"] = "10%"
bar._option.get("yAxis")[0]["axisTick"] = False
bar._option.get("xAxis")[0]["axisTick"] = False

在此就不一一举例查看效果了。

python pyecharts生成图表相关推荐

  1. python数据可视化--pyecharts生成图表

    [python可视化系列]python数据可视化利器--pyecharts echarts官网 一.前言 echarts是什么?下面是来自官方的介绍: ECharts,缩写来自Enterprise C ...

  2. excel的数据通过pyecharts生成图表,插入ppt

    一.安装pyecharts,xlrd 直接采用pip install pyecharts,会安装最新版本,应该是1.2.1,很多接口已经变化了,这里还是安装老版本,且不需要ssl和https认证,命令 ...

  3. python批量生成图表_教你用Python自动读取数据生成图表,产生的效益很可观

    厌烦了每次都要在Excel里拖动数据来生成图形吧,这篇文章里,教你用Python自动读取Excel数据生成图表,然后Python 使用XlsxWriter模块在Excel工作表中绘制带有数据表的柱形图 ...

  4. python excel生成图表_python excel 之 按格式生成图表和数据

    python excel 针对python 对excel的操作目前有已经有很多库可以使用, 比如最常用的读写库xlrd,xlwt,xlutils 对xlsx.xlsm读写的openpyxl 针对xls ...

  5. linux服务器log日志通过python统计生成图表(LOG日志统计一)

    这已经不是第一次遇到了,服务器的CPU或IO突然剧增,或者APP响应突然超慢,这个时候需要查看日志,看看接口有木有异常. 利用linux特有的grep.awk了可以快速统计,指定时间段的接口出现次数, ...

  6. python绘制动态图表怎么存下来_用python如何实现导入excel数据后自动生成图表?python如何实现交互式动态图表?...

    这个需求涉及的环节太多了.导入excel文件,获取数据 -- 需要xlrd模块把数据导入python 2. 设定输出图表类型 -- 需要matplot模块.根据数据复杂度,可能需要ETL,那么需要pa ...

  7. python提取excel前十行生成图_Python读取Excel数据生成图表 v2.0

    Python读取Excel数据生成图表 v2.0 一.需求背景 自己一直在做一个周基金定投模拟,每周需要添加一行数据,并生成图表.以前一直是用Excel实现的.但数据行多后,图表大小调整总是不太方便, ...

  8. JIra+Python+Pyechart 通过分析jira数据生成图表并展示,出具质量可视化的测试报告

    背景: 我本人不愿意写测试报告,但领导规定每个迭代后都需要发一份测试报告,让我比较难受(不是不会写,主要是测试报告内容比较详实,几乎没有人会细看),没有人看就=流于形式 那么,有没有一种方法,既满足了 ...

  9. python动态交互式图表库_干货 | 使用pyecharts绘制交互式动态地图

    干货 | 使用pyecharts绘制交互式动态地图 说到pyecharts,相信很多人不会陌生,一个优秀的python可视化包. pyecharts是中国人开发的,相比较matplotlib.seab ...

最新文章

  1. 在linux上使用cvs命令
  2. C# 读取Excel中的时间
  3. 如何显示服务器上的图片,显示服务器上的图片怎么写
  4. Boost中的Timer的使用——计算时间流逝
  5. 一次 .NET Core 中玩锁的经历:ManualResetEventSlim, SemaphoreSlim
  6. DotNetCore跨平台~配置文件与配置代码如何共存
  7. 数据这么多,且看R语言怎么处理!
  8. JEECG_3.7.2新版本入门讲解—UI标签库专题
  9. 企业级SpringBoot教程(十一)springboot集成swagger2,构建Restful API
  10. python -- configparse读取配置文件
  11. ubuntu 14.04系统DHCP服务器搭建
  12. Mysql-savepoint
  13. [从零开始学习FPGA编程-27]:进阶篇 - 基本组合电路-数据比较器(Verilog语言)
  14. 计算机软件著作权可以同时寄多份,软件著作权可以挂几个人,最多几个作者?...
  15. 于娟视频:活着就是王道
  16. BZOJ 1778: [Usaco2010 Hol]Dotp 驱逐猪猡
  17. NFC应用(二)读写器模式
  18. 解决opencv保存视频打不开问题
  19. python中的format什么意思中文-python中format函数什么意思
  20. 数据库SQL注入漏洞

热门文章

  1. uniApp APP端调起微信支付失败errCode:-100的踩坑
  2. LEADTOOLS V20,史无前例荣耀归来!!!
  3. Java NIO Selector , SelectionKey , SocketChannel , ServerSocketChannel
  4. NYOJ 456 邮票分你一半
  5. 机器人史宾_史宾机器人:重启
  6. HBase原理–所有Region切分的细节都在这里了
  7. 怎么查服务器域名 mac系统,苹果6s肿么查看服务器域名
  8. iOS比较常用的第三方及实例(不断更新中)
  9. 学术之声 | 专访邵俊教授:区块链用技术保证在链上说话算话
  10. Cesium加载建筑物模型(shp转Geojson\3Dtiles)