示例#1
0
def test_mouse_click():
    bar = Bar("我的第一个图表", "这里是副标题")
    bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
            [5, 20, 36, 10, 75, 90])
    bar.on(events.MOUSE_CLICK, on_click)
    assert "function on_click(" in bar._repr_html_()
示例#2
0
from pyecharts import Bar

bar = Bar("我的第一个图表", "这里是副标题")
bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        [5, 20, 36, 10, -75, 90],
        is_more_utils=True,
        is_convert=True)
bar.render('./html/spread.html')
示例#3
0
                       db='maoyan',
                       charset='utf8mb4')
cursor = conn.cursor()
sql = "select * from films"
db = pd.read_sql(sql, conn)
df = db.sort_values(by="people", ascending=False)
dom = df[['name', 'people']]

attr = np.array(dom['name'][0:10])
v1 = np.array(dom['people'][0:10])
attr = ["{}".format(i.replace(':无限战争', '')) for i in attr]
v1 = ["{}".format(float('%.2f' % (float(i) / 10000))) for i in v1]

bar = Bar("2018年电影人气TOP10(万人)",
          title_pos='center',
          title_top='18',
          width=800,
          height=400)
bar.add("",
        attr,
        v1,
        is_convert=True,
        xaxis_min=10,
        yaxis_label_textsize=12,
        is_yaxis_boundarygap=True,
        yaxis_interval=0,
        is_label_show=True,
        is_legend_show=False,
        label_pos='right',
        is_yaxis_inverse=True,
        is_splitline_show=False)
示例#4
0
# -*- coding: utf-8 -*-

import pandas as pd
from pandas import DataFrame
from pyecharts import Bar, Grid, Page

# dataframe preparation
data = pd.read_excel('D:\Python\Test_Codes\\workload.XLSX',
                     sheet_name='Sheet2',
                     header=0)
df_raw = DataFrame(data)

# General settings of chart overview
bar1 = Bar(title='Number of Dialog Steps',
           title_pos='left',
           width=1000,
           height=500,
           renderer='canvas')

bar1.use_theme('essos')

bar1.add('Number of Dialog Steps',
         df_raw['Task Type Name'],
         df_raw['Number of Dialog Steps'],
         is_stack=True,
         mark_line=['average', 'max'],
         mark_point=['max'],
         mark_point_symbolsize=100,
         is_label_show=True,
         legend_selectedmode='single',
         legend_pos=400,
示例#5
0
from __future__ import unicode_literals
from pyecharts import Bar
from pyecharts.conf import PyEchartsConfig
from pyecharts.engine import EchartsEnvironment
from pyecharts.utils import write_utf8_html_file

attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar("柱状图数据堆叠示例")
bar.add("商家A", attr, v1, is_stack=True)
bar.add("商家B", attr, v2, is_stack=True)
config = PyEchartsConfig(echarts_template_dir='my_tpl',
                         jshost='https://cdn.bootcss.com/echarts/3.6.2')
env = EchartsEnvironment(pyecharts_config=config)
tpl = env.get_template(r'D:\python\tpl_demo.html')
html = tpl.render(bar=bar)
write_utf8_html_file('my_tpl_demo2.html', html)
示例#6
0
        shadow=False,
        startangle=90)
plt.axis("equal")
plt.show()

#直方图
np.random.seed(0)
mu, sigma = 100, 20
a = np.random.normal(mu, sigma, size=100)

plt.hist(a, 10, normed=1, histtype="stepfilled", facecolor="b", alpha=0.75)
plt.show()

from pyecharts import Bar

bar = Bar("我的第一个图表")
bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90])
bar.print_echarts_options()
bar.render()
exit(0)

df1 = pd.DataFrame(np.arange(12.).reshape(3, 4), columns=list("abcd"))
df1.plot(kind="box", fontsize=12)
plt.show()

data1 = {"key": ["a", "a", "b", "b"], "name": [1, 2, 3, 4]}
frame1 = pd.DataFrame(data1)
seri = pd.Series([1, 1, 1, 1])
seri.name = "name2"
frame1[seri.name] = seri
示例#7
0
# coding:utf-8
# 导入读取Excel的库
import xlrd

# 导入需要读取Excel表格的路径
data = xlrd.open_workbook(r'测试.xlsx')
table = data.sheets()[0]
y = ''
# 将列的值存入字符串
y = table.col_values(2)  # 读取列的值
# 导入pyechats库
from pyecharts import Bar
import numpy as np

t = np.linspace(1, 1000000, len(y))  # 等间隔取值
bar = Bar("文章阅读量展示", "统计如下")  # 主副标题
bar.add("博客文章阅读量折线图展示", t, y, is_more_utils=True)  # 标题
bar.show_config()  # 展示HTML源代码
bar.render(r"bokezhexiantu.html")  # 保存到本地bokezhexiantu.html




示例#8
0
    # 过滤房价为0的无效数据
    df = df[df.price > 0]
    # # 去除重复行
    # df = df.drop_duplicates()
    print("row number is {0}".format(len(df.index)))

    ####################################################
    # 最贵的小区排名
    ####################################################
    df.sort_values("price", ascending=False, inplace=True)
    num = 5
    print(df.head(num))
    city = df["city_ch"][0]
    xqs = df["xiaoqu"][0:num]
    prices = df["price"][0:num]
    bar = Bar("{0}小区均价".format(city))
    bar.add("小区均价前{0}名".format(num),
            xqs,
            prices,
            is_stack=True,
            is_label_show=True,
            xaxis_interval=0,
            xaxis_rotate=45)
    bar.render(path="xiaoqu.html")

    ####################################################
    # 区县均价排名
    ####################################################
    district_df = df.groupby('district').mean()
    district_df = district_df.round(0)
    district_df.sort_values("price", ascending=False, inplace=True)
示例#9
0
文件: bar.py 项目: mikimaus78/skl001
__author__ = 'zoulida'
#导入柱状图-Bar
from pyecharts import Bar
#设置行名
columns = [
    "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
    "Nov", "Dec"
]
#设置数据
data1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
data2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
#设置柱状图的主标题与副标题
bar = Bar("柱状图", "一年的降水量与蒸发量")
#添加柱状图的数据及配置项
bar.add("降水量",
        columns,
        data1,
        mark_line=["average"],
        mark_point=["max", "min"])
bar.add("蒸发量",
        columns,
        data2,
        mark_line=["average"],
        mark_point=["max", "min"])
#生成本地文件(默认为.html文件)
bar.render()
示例#10
0
import pandas as pd
import matplotlib.pyplot as plt
from pyecharts import Line, Bar
from pyecharts.engine import create_default_environment

'''评论数变化情况'''

df=pd.read_csv('Sina_Finance_Comments_All_20180811_Cleaned.csv',encoding='utf-8')
print(df.head())
# plt.plot(df.stamp,df.cmntcount)
# plt.show()

print('===================================================')
df_ymdcount=df.groupby('time_ymd')['cmntcount'].count()
print(df_ymdcount)
line1=Line('每日评论数变化情况')
line1.add('日期',df_ymdcount.index,df_ymdcount.values,is_label_show=True,line_type='dotted')
env=create_default_environment('html')
env.render_chart_to_file(line1, path='line1.html')

print('===================================================')
df_mdhcount=df.groupby('time_mdh')['cmntcount'].count()
print(df_mdhcount)
#折线图
line2=Line('每小时评论数')
line2.add('小时',df_mdhcount.index,df_mdhcount.values,is_label_show=True,line_type='dotted')
env.render_chart_to_file(line2,path='line2.html')
#柱状图
bar=Bar('每小时评论数')
bar.add('小时',df_mdhcount.index,df_mdhcount.values,is_label_show=True,line_type='dotted')
env.render_chart_to_file(bar,path='bar.html')
示例#11
0
print(sfz)
sfzset = set(sfz)
# print(ageset)
for year in sfzset:
    if year.isdigit():
        # 判断count是不是字符即是否可被int
        if int(year) > 1990 and int(year) < 2000:
            # 判断count的值的区间
            num.append(sfz.count(year))
            age.append(str(year))
            # print(year,sfz.count(year))
        else:
            pass
    else:
        pass
print(age)
print(num)
bar = Bar("年龄统计")
bar.add("年龄", age, num)
bar.show_config()
bar.render()
# if int(count)>1990 and int(count)<2000:
#     print(count,age.count(count))
# else:
#     pass
cursor.close()
# 关闭游标
conn.close()
# 关闭链接
# 使用饼图进行性别分析
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2018-09-14 20:26:07
# @Author  : cdl ([email protected])
# @Link    : https://github.com/cdlwhm1217096231/python3_spider
# @Version : $Id$

from pyecharts import Bar

bar = Bar("图表1", "副标题")
bar.use_theme('dark')  # 使用主题
bar.add("服装", ["衬衫", "羊毛衫", "毛衣", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90],
        is_more_utils=True)
bar.render(path='demo1.png')
示例#13
0
文件: report.py 项目: qqpals/opsweb
def resource_report():
    try:
        form = MyForm.Form_resource_report()
        days = tools.http_args(request, 'days')
        date = datetime.datetime.now()
        db_server = db_idc.idc_servers
        if days:
            days = int(days)
            update_date = date - datetime.timedelta(days=days)
        else:
            days = 30
            update_date = date - datetime.timedelta(days=30)
        datazoom = True
        if days == 30:
            datazoom = False
        Bars = {}
        titles = {30: '近一个月', 90: '近三个月', 180: '近六个月', 360: '近一年内'}
        db_third = db_idc.third_resource
        db_project = db_op.project_list
        vals = db_project.query.with_entities(
            db_project.update_date, func.count(db_project.update_date)).filter(
                and_(db_project.resource == 'tomcat',
                     db_project.update_date != '',
                     db_project.update_date >= update_date)).group_by(
                         db_project.update_date).all()
        if vals:
            attrs = [val[0] for val in vals]
            datas = [val[-1] for val in vals]
            tomcat_bar = Bar("tomcat(%s)" % titles[days],
                             width='110%',
                             height='100%',
                             title_pos='center',
                             title_text_size=14)
            tomcat_bar.add("",
                           attrs,
                           datas,
                           is_label_show=True,
                           is_toolbox_show=False,
                           legend_orient='vertical',
                           legend_pos='right',
                           xaxis_interval=0,
                           is_random=True,
                           xaxis_rotate=15,
                           is_datazoom_show=datazoom,
                           datazoom_type='both')
            Bars['tomcat'] = tomcat_bar
        vals = db_third.query.with_entities(
            db_third.update_date, func.count(db_third.update_date)).filter(
                and_(db_third.resource_type == 'redis',
                     db_third.update_date != '',
                     db_third.update_date >= update_date)).group_by(
                         db_third.update_date).all()
        if vals:
            attrs = [val[0] for val in vals]
            datas = [val[-1] for val in vals]
            redis_bar = Bar("redis(%s)" % titles[days],
                            width='110%',
                            height='100%',
                            title_pos='center',
                            title_text_size=14)
            redis_bar.add("",
                          attrs,
                          datas,
                          is_label_show=True,
                          is_toolbox_show=False,
                          legend_orient='vertical',
                          legend_pos='right',
                          xaxis_interval=0,
                          is_random=True,
                          xaxis_rotate=15,
                          is_datazoom_show=datazoom,
                          datazoom_type='both')
            Bars['redis'] = redis_bar
        vals = db_third.query.with_entities(
            db_third.update_date, func.count(db_third.update_date)).filter(
                and_(db_third.resource_type == 'redis',
                     db_third.update_date != '')).group_by(
                         db_third.update_date).all()
        if vals:
            attrs = [val[0] for val in vals]
            datas = [val[-1] for val in vals]
            mysql_bar = Bar("mysql(%s)" % titles[days],
                            width='110%',
                            height='100%',
                            title_pos='center',
                            title_text_size=14)
            mysql_bar.add("",
                          attrs,
                          datas,
                          is_label_show=True,
                          is_toolbox_show=False,
                          legend_orient='vertical',
                          legend_pos='right',
                          xaxis_interval=0,
                          is_random=True,
                          xaxis_rotate=15,
                          is_datazoom_show=datazoom,
                          datazoom_type='both')
            Bars['mysql'] = mysql_bar
        vals = db_third.query.with_entities(
            db_third.update_date, func.count(db_third.update_date)).filter(
                and_(db_third.resource_type == 'redis',
                     db_third.update_date != '')).group_by(
                         db_third.update_date).all()
        if vals:
            attrs = [val[0] for val in vals]
            datas = [val[-1] for val in vals]
            nginx_bar = Bar("nginx(%s)" % titles[days],
                            width='110%',
                            height='100%',
                            title_pos='center',
                            title_text_size=14)
            nginx_bar.add("",
                          attrs,
                          datas,
                          is_label_show=True,
                          is_toolbox_show=False,
                          legend_orient='vertical',
                          legend_pos='right',
                          xaxis_interval=0,
                          is_random=True,
                          xaxis_rotate=15,
                          is_datazoom_show=datazoom,
                          datazoom_type='both')
            Bars['nginx'] = nginx_bar
        try:
            td = time.strftime("%Y-%m-%d", time.localtime())
            std = datetime.datetime.now() - datetime.timedelta(days=180)
            std = std.strftime("%Y-%m-%d")
            if RC.exists('op_web_vm_vales_%s' % td) and RC.exists(
                    'op_web_py_vales_%s' % td):
                vm_vals = eval(RC.get('op_web_vm_vales_%s' % td))
                py_vals = eval(RC.get('op_web_py_vales_%s' % td))
            else:
                vm_vals = db_server.query.with_entities(
                    db_server.purch_date,
                    func.count(db_server.purch_date)).filter(
                        and_(db_server.host_type == 'vm',
                             db_server.purch_date > std)).group_by(
                                 db_server.purch_date).all()
                RC.set('op_web_vm_vales_%s' % td, vm_vals)
                RC.expire('op_web_vm_vales_%s', 86400)
                py_vals = db_server.query.with_entities(
                    db_server.purch_date,
                    func.count(db_server.purch_date)).filter(
                        and_(db_server.host_type == 'physical',
                             db_server.purch_date > std)).group_by(
                                 db_server.purch_date).all()
                RC.set('op_web_py_vales_%s' % td, py_vals)
                RC.expire('op_web_py_vales_%s', 86400)
        except Exception as e:
            logging.error(e)
        try:
            server_bar = Bar("近6个月新增服务器数量",
                             title_pos='center',
                             title_text_size=12,
                             width='110%',
                             height='230px')
            attrs = sorted(
                set([val[0] for val in vm_vals if val] +
                    [val[0] for val in py_vals if val]))
            vm_vals = {val[0]: val[1] for val in vm_vals}
            py_vals = {val[0]: val[1] for val in py_vals}
            for attr in attrs:
                if attr not in vm_vals:
                    vm_vals[attr] = 0
                if attr not in py_vals:
                    py_vals[attr] = 0
            vm_vals = sorted(vm_vals.items(), key=lambda item: item[0])
            vm_vals = [val[1] for val in vm_vals]
            py_vals = sorted(py_vals.items(), key=lambda item: item[0])
            py_vals = [val[1] for val in py_vals]
            attrs = ['-'.join(val.split('-')[1:]) for val in attrs]
            vm_counts = reduce(lambda x, y: x + y, vm_vals)
            server_bar.add('虚拟机%s台' % vm_counts,
                           attrs,
                           vm_vals,
                           is_label_show=True,
                           is_toolbox_show=False,
                           xaxis_interval=0,
                           xaxis_rotate=25,
                           legend_pos='70%')
            py_counts = reduce(lambda x, y: x + y, py_vals)
            server_bar.add('物理机%s台' % py_counts,
                           attrs,
                           py_vals,
                           is_label_show=True,
                           is_toolbox_show=False,
                           xaxis_interval=0,
                           xaxis_rotate=25,
                           legend_pos='70%')
        except Exception as e:
            logging.error(e)
    except Exception as e:
        logging.error(e)
        return redirect(url_for('error'))
    return render_template('resource_report.html',
                           Bars=Bars,
                           form=form,
                           days=days,
                           server_bar=server_bar)
示例#14
0
文件: report.py 项目: qqpals/opsweb
def server_used():
    try:
        try:
            PIES = []
            INFOS = []
            ATTRS = []
            if RC_CLUSTER.exists('op_zabbix_server_load_top'):
                dict_load = eval(RC_CLUSTER.get('op_zabbix_server_load_top'))
                bar_load = Bar("线上服务器cpu使用率TOP20",
                               width='110%',
                               height='100%',
                               title_pos='center',
                               title_text_size=14)
                attrs = [val[0] for val in dict_load]
                vals = [int(val[1]) for val in dict_load]
                ATTRS.extend(attrs)
                bar_load.add("",
                             attrs,
                             vals,
                             is_label_show=True,
                             is_toolbox_show=False,
                             legend_orient='vertical',
                             legend_pos='right',
                             xaxis_interval=0,
                             is_random=True,
                             yaxis_formatter='%',
                             xaxis_rotate=15)
                INFOS.append(bar_load)
            if RC_CLUSTER.exists('op_zabbix_server_mem_top'):
                dict_mem = eval(RC_CLUSTER.get('op_zabbix_server_mem_top'))
                bar_mem = Bar("线上服务器内存使用率TOP20",
                              width='110%',
                              height='100%',
                              title_pos='center',
                              title_text_size=14)
                attrs = [val[0] for val in dict_mem]
                vals = [int(val[1]) for val in dict_mem]
                ATTRS.extend(attrs)
                bar_mem.add("",
                            attrs,
                            vals,
                            is_label_show=True,
                            is_toolbox_show=False,
                            legend_orient='vertical',
                            legend_pos='right',
                            xaxis_interval=0,
                            is_random=True,
                            yaxis_formatter='%',
                            xaxis_rotate=15)
                INFOS.append(bar_mem)
            if RC_CLUSTER.exists('op_zabbix_server_openfile_top'):
                dict_openfile = eval(
                    RC_CLUSTER.get('op_zabbix_server_openfile_top'))
                bar_openfile = Bar("线上服务器openfile值TOP20",
                                   width='110%',
                                   height='100%',
                                   title_pos='center',
                                   title_text_size=14)
                attrs = [val[0] for val in dict_openfile]
                vals = [int(val[1]) for val in dict_openfile]
                ATTRS.extend(attrs)
                bar_openfile.add("",
                                 attrs,
                                 vals,
                                 is_label_show=True,
                                 is_toolbox_show=False,
                                 legend_orient='vertical',
                                 legend_pos='right',
                                 xaxis_interval=0,
                                 is_random=True,
                                 xaxis_rotate=15)
                INFOS.append(bar_openfile)
        except Exception as e:
            logging.error(e)
        try:
            free_list = []
            if RC_CLUSTER.exists('op_zabbix_free_servers'):
                free_servers = eval(RC_CLUSTER.get('op_zabbix_free_servers'))
                free_servers = [host for host in free_servers]
                free_servers.sort()
                # 导出服务器主机列表
                tables = ['主机名']
                search_key = 'search_results_%s' % g.token
                export_values = [[host] for host in free_servers]
                export_values.insert(0, tables)
                RC.set(search_key, export_values)
                host_count = len(free_servers)
                # 服务器列表展示
                free_list = [
                    free_servers[i * 5:(i + 1) * 5]
                    for i in range(len(free_servers) // 5)
                ]
        except Exception as e:
            logging.error(e)
        if ATTRS:
            db_project = db_op.project_list
            db_third = db_idc.third_resource
            db_server = db_idc.idc_servers
            db_project_third = db_op.project_third
            hosts = db_server.query.with_entities(db_server.ip).filter(
                db_server.hostname.in_(tuple(set(ATTRS)))).all()
            if hosts:
                try:
                    # 应用服务占比
                    hosts = tuple([host[0] for host in hosts])
                    selfs = db_project.query.with_entities(
                        db_project.resource,
                        func.count(db_project.resource)).filter(
                            db_project.ip.in_(hosts)).group_by(
                                db_project.resource).all()
                    thirds = db_third.query.with_entities(
                        db_third.resource_type,
                        func.count(db_third.resource_type)).filter(
                            db_third.ip.in_(hosts)).group_by(
                                db_third.resource_type).all()
                    vals = selfs + thirds
                    if vals:
                        pie_app = Pie("TOP20应用服务占比",
                                      width='100%',
                                      height='100%',
                                      title_pos='center',
                                      title_text_size=14)
                        attrs = [val[0] for val in vals]
                        vals = [int(val[1]) for val in vals]
                        pie_app.add("",
                                    attrs,
                                    vals,
                                    is_label_show=True,
                                    is_toolbox_show=False,
                                    is_legend_show=False,
                                    xaxis_interval=0,
                                    is_random=True)
                        PIES.append(pie_app)
                    # 线上项目占比
                    self_id = db_project.query.with_entities(
                        db_project.id).filter(db_project.ip.in_(hosts)).all()
                    third_id = db_third.query.with_entities(
                        db_third.id).filter(db_third.ip.in_(hosts)).all()
                    ids = self_id + third_id
                    ids = tuple([id[0] for id in ids])
                    vals = db_project_third.query.with_entities(
                        db_project_third.project,
                        func.count(db_project_third.project)).filter(
                            and_(db_project_third.project_id.in_(ids),
                                 db_project_third.third_id.in_(ids))).group_by(
                                     db_project_third.project).all()
                    if vals:
                        pie_project = Pie("TOP20线上项目占比",
                                          width='100%',
                                          height='100%',
                                          title_pos='center',
                                          title_text_size=14)
                        attrs = [val[0] for val in vals]
                        vals = [int(val[1]) for val in vals]
                        pie_project.add("",
                                        attrs,
                                        vals,
                                        is_label_show=True,
                                        is_toolbox_show=False,
                                        legend_orient='vertical',
                                        legend_pos='left',
                                        xaxis_interval=0,
                                        is_random=True)
                        PIES.append(pie_project)
                except Exception as e:
                    logging.error(e)
    except Exception as e:
        logging.error(e)
        return redirect(url_for('error'))
    return render_template('server_used.html',
                           INFOS=INFOS,
                           PIES=PIES,
                           host_count=host_count,
                           free_list=free_list)
if __name__ == '__main__':
    gender_htmlfile = './../../Resources/htmlfiles/article_comment_gender.html'
    location_htmlfile = './../../Resources/htmlfiles/loaction.html'
    business_htmlfile = './../../Resources/htmlfiles/business.html'
    major_htmlfile = './../../Resources/htmlfiles/major.html'
    comment_class_file = './../../Resources/htmlfiles/comment_class.html'
    jsonfile1 = './../../Resources/jsonfiles/processed_zh_comment.json'
    comment_txt = './../../Resources/CutWordPath/sentiment_comment.txt'

    dict_comment = Read_file(jsonfile1)
    attr = list(dict_comment.keys())
    value = []
    for key in attr:
        value.append(len(dict_comment[key]))
    bar = Bar('带评论的文章的类别分布')
    bar.add('类别', attr, value, is_label_show=True, make_point=['average'])
    bar.show_config()
    bar.render(comment_class_file)

    # 提取需要的信息
    article_gender_list, article_place_list, article_business_list, article_major_list, articale_comment_list = extract_article_list(
        dict_comment)

    plt_Pie("社会话题的性别分布", article_gender_list, gender_htmlfile)
    print("评论用户性别分布执行结束,%s文件生成" % gender_htmlfile)

    plt_place(article_place_list, location_htmlfile)
    print("评论用户位置分布执行结束,%s文件生成" % location_htmlfile)

    plt_business("评论用户行业分布", article_business_list, business_htmlfile)
示例#16
0
    def kline_echarts(self, code=None):
        def kline_formater(param):
            return param.name + ':' + vars(param)

        """plot the market_data"""
        if code is None:
            path_name = '.' + os.sep + 'QA_' + self.type + \
                '_codepackage_' + self.if_fq + '.html'
            kline = Kline('CodePackage_' + self.if_fq + '_' + self.type,
                          width=1360,
                          height=700,
                          page_title='QUANTAXIS')

            bar = Bar()
            data_splits = self.splits()

            for ds in data_splits:
                data = []
                axis = []
                if ds.type[-3:] == 'day':
                    datetime = np.array(ds.date.map(str))
                else:
                    datetime = np.array(ds.datetime.map(str))
                ohlc = np.array(ds.data.loc[:,
                                            ['open', 'close', 'low', 'high']])

                kline.add(ds.code[0],
                          datetime,
                          ohlc,
                          mark_point=["max", "min"],
                          is_datazoom_show=True,
                          datazoom_orient='horizontal')
            return kline

        else:
            data = []
            axis = []
            ds = self.select_code(code)
            data = []
            #axis = []
            if self.type[-3:] == 'day':
                datetime = np.array(ds.date.map(str))
            else:
                datetime = np.array(ds.datetime.map(str))

            ohlc = np.array(ds.data.loc[:, ['open', 'close', 'low', 'high']])
            vol = np.array(ds.volume)
            kline = Kline('{}__{}__{}'.format(code, self.if_fq, self.type),
                          width=1360,
                          height=700,
                          page_title='QUANTAXIS')
            bar = Bar()
            kline.add(
                self.code,
                datetime,
                ohlc,
                mark_point=["max", "min"],
                # is_label_show=True,
                is_datazoom_show=True,
                is_xaxis_show=False,
                # is_toolbox_show=True,
                tooltip_formatter='{b}:{c}',  # kline_formater,
                # is_more_utils=True,
                datazoom_orient='horizontal')

            bar.add(self.code,
                    datetime,
                    vol,
                    is_datazoom_show=True,
                    datazoom_xaxis_index=[0, 1])

            grid = Grid(width=1360, height=700, page_title='QUANTAXIS')
            grid.add(bar, grid_top="80%")
            grid.add(kline, grid_bottom="30%")
            return grid
示例#17
0
                      user='******',
                      password='******',
                      db='www_802k_cn',
                      charset='utf8')
sql = "select * from dd_chapter"
df = pd.read_sql(sql, con, index_col="id")
df

# In[13]:

x = df['mch'].index

# In[14]:

y = df['pernums'].values

# In[20]:

attr = ["{}条".format(i) for i in x]
# v1 = [random.randint(1, 30) for _ in range(30)]
bar = Bar("每条链接引入人数")
bar.add(
    "",
    attr,
    y,
    is_datazoom_show=True,
    datazoom_type="inside",
    datazoom_range=[10, 25],
)
bar.render('show_increase.html')
def draw_citys_pic(csv_file):
    page = Page(csv_file + ":评论城市分析")
    info = count_city(csv_file)
    geo = Geo("",
              "Ctipsy原创",
              title_pos="center",
              width=1200,
              height=600,
              background_color='#404a59',
              title_color="#fff")
    while True:  # 二次筛选,和pyecharts支持的城市库进行匹配,如果报错则删除该城市对应的统计
        try:
            attr, val = geo.cast(info)
            geo.add("",
                    attr,
                    val,
                    visual_range=[0, 300],
                    visual_text_color="#fff",
                    is_geo_effect_show=False,
                    is_piecewise=True,
                    visual_split_number=6,
                    symbol_size=15,
                    is_visualmap=True)
        except ValueError as e:
            e = str(e)
            e = e.split("No coordinate is specified for ")[1]  # 获取不支持的城市名称
            info.pop(e)
        else:
            break
    info = sorted(info.items(), key=lambda x: x[1], reverse=False)  # list排序
    # print(info)
    info = dict(info)  # list转dict
    # print(info)
    attr, val = [], []
    for key in info:
        attr.append(key)
        val.append(info[key])

    geo1 = Geo("",
               "评论城市分布",
               title_pos="center",
               width=1200,
               height=600,
               background_color='#404a59',
               title_color="#fff")
    geo1.add("",
             attr,
             val,
             visual_range=[0, 300],
             visual_text_color="#fff",
             is_geo_effect_show=False,
             is_piecewise=True,
             visual_split_number=10,
             symbol_size=15,
             is_visualmap=True,
             is_more_utils=True)
    # geo1.render(csv_file + "_城市dotmap.html")
    page.add_chart(geo1)
    geo2 = Geo(
        "",
        "评论来源热力图",
        title_pos="center",
        width=1200,
        height=600,
        background_color='#404a59',
        title_color="#fff",
    )
    geo2.add("",
             attr,
             val,
             type="heatmap",
             is_visualmap=True,
             visual_range=[0, 50],
             visual_text_color='#fff',
             is_more_utils=True)
    # geo2.render(csv_file+"_城市heatmap.html")  # 取CSV文件名的前8位数
    page.add_chart(geo2)
    bar = Bar("", "评论来源排行", title_pos="center", width=1200, height=600)
    bar.add("",
            attr,
            val,
            is_visualmap=True,
            visual_range=[0, 100],
            visual_text_color='#fff',
            mark_point=["average"],
            mark_line=["average"],
            is_more_utils=True,
            is_label_show=True,
            is_datazoom_show=True,
            xaxis_rotate=45)
    # bar.render(csv_file+"_城市评论bar.html")  # 取CSV文件名的前8位数
    page.add_chart(bar)
    pie = Pie("", "评论来源饼图", title_pos="right", width=1200, height=600)
    pie.add("",
            attr,
            val,
            radius=[20, 50],
            label_text_color=None,
            is_label_show=True,
            legend_orient='vertical',
            is_more_utils=True,
            legend_pos='left')
    # pie.render(csv_file + "_城市评论Pie.html")  # 取CSV文件名的前8位数
    page.add_chart(pie)
    page.render(csv_file + "_城市评论分析汇总.html")
# ! /usr/bin/env python
# - * - coding:utf-8 - * -
# __author__ : KingWolf
# createtime : 2018/11/23 23:29

from pyecharts import Bar

#创建Bar柱形图对象
bar = Bar(title='狼胸_主标题', subtitle='kingwolf_副标题')

#使用主题
bar.use_theme('dark')

# 主要方法,用于添加图表的数据和设置各种配置项:第一个参数是name,放在图形的右上角展示,第二个参数是X轴参数,显示的是列表或者元祖,第三个参数是Y轴参数,显示的是列表或者元祖
bar.add("鞋袜", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90])

#打印输出图表的所有配置项
# bar.print_echarts_options()

#默认将会在根目录下生成一个 render.html 的文件,支持 path 参数,设置文件保存位置,如 render(r"e:\my_first_chart.html"),文件用浏览器打开。
bar.render('render2.html')
def score_draw(csv_file):
    page = Page(csv_file + ":评论等级分析")
    score, date, val, score_list = [], [], [], []
    result = {}
    path = os.path.abspath(os.curdir)
    csv_file = path + "\\" + csv_file + ".csv"
    csv_file = csv_file.replace('\\', '\\\\')
    d = pd.read_csv(csv_file, engine='python', encoding='utf-8')[[
        'score', 'date'
    ]].dropna()  # 读取CSV转为dataframe格式,并丢弃评论为空的记录
    for indexs in d.index:  # 一种遍历df行的方法(下面还有第二种,iterrows)
        score_list.append(tuple(
            d.loc[indexs].values[:]))  # 目前只找到转换为tuple然后统计相同元素个数的方法
    # print("有效评分总数量为:",len(score_list), " 条")
    for i in set(list(score_list)):
        result[i] = score_list.count(i)  # dict类型 ('很差', '2018-04-28'): 55
    info = []
    for key in result:
        score = key[0]
        date = key[1]
        val = result[key]
        info.append([score, date, val])
    info_new = DataFrame(info)  # 将字典转换成为数据框
    info_new.columns = ['score', 'date', 'votes']
    info_new.sort_values('date',
                         inplace=True)  # 按日期升序排列df,便于找最早date和最晚data,方便后面插值
    # print("first df", info_new)
    # 以下代码用于插入空缺的数据,每个日期的评分类型应该有5中,依次遍历判断是否存在,若不存在则往新的df中插入新数值
    mark = 0
    creat_df = pd.DataFrame(columns=['score', 'date',
                                     'votes'])  # 创建空的dataframe
    for i in list(info_new['date']):
        location = info_new[(info_new.date == i)
                            & (info_new.score == "力荐")].index.tolist()
        if location == []:
            creat_df.loc[mark] = ["力荐", i, 0]
            mark += 1
        location = info_new[(info_new.date == i)
                            & (info_new.score == "推荐")].index.tolist()
        if location == []:
            creat_df.loc[mark] = ["推荐", i, 0]
            mark += 1
        location = info_new[(info_new.date == i)
                            & (info_new.score == "还行")].index.tolist()
        if location == []:
            creat_df.loc[mark] = ["还行", i, 0]
            mark += 1
        location = info_new[(info_new.date == i)
                            & (info_new.score == "较差")].index.tolist()
        if location == []:
            creat_df.loc[mark] = ["较差", i, 0]
            mark += 1
        location = info_new[(info_new.date == i)
                            & (info_new.score == "很差")].index.tolist()
        if location == []:
            creat_df.loc[mark] = ["很差", i, 0]
            mark += 1
    info_new = info_new.append(creat_df.drop_duplicates(), ignore_index=True)
    score_list = []
    info_new.sort_values('date',
                         inplace=True)  # 按日期升序排列df,便于找最早date和最晚data,方便后面插值
    # print(info_new)
    for index, row in info_new.iterrows():  # 第二种遍历df的方法
        score_list.append([row['date'], row['votes'], row['score']])
    tr = ThemeRiver()
    tr.add(['力荐', '推荐', '还行', '较差', '很差'],
           score_list,
           is_label_show=True,
           is_more_utils=True)
    page.add_chart(tr)

    attr, v1, v2, v3, v4, v5 = [], [], [], [], [], []
    attr = list(sorted(set(info_new['date'])))
    bar = Bar()
    for i in attr:
        v1.append(
            int(info_new[(info_new['date'] == i)
                         & (info_new['score'] == "力荐")]['votes']))
        v2.append(
            int(info_new[(info_new['date'] == i)
                         & (info_new['score'] == "推荐")]['votes']))
        v3.append(
            int(info_new[(info_new['date'] == i)
                         & (info_new['score'] == "还行")]['votes']))
        v4.append(
            int(info_new[(info_new['date'] == i)
                         & (info_new['score'] == "较差")]['votes']))
        v5.append(
            int(info_new[(info_new['date'] == i)
                         & (info_new['score'] == "很差")]['votes']))
    bar.add("力荐", attr, v1, is_stack=True)
    bar.add("推荐", attr, v2, is_stack=True)
    bar.add("还行", attr, v3, is_stack=True)
    bar.add("较差", attr, v4, is_stack=True)
    bar.add("很差",
            attr,
            v5,
            is_stack=True,
            is_convert=True,
            mark_line=["average"],
            is_more_utils=True)
    page.add_chart(bar)

    line = Line()
    line.add("力荐", attr, v1, is_stack=True)
    line.add("推荐", attr, v2, is_stack=True)
    line.add("还行", attr, v3, is_stack=True)
    line.add("较差", attr, v4, is_stack=True)
    line.add("很差",
             attr,
             v5,
             is_stack=True,
             is_convert=False,
             mark_line=["average"],
             is_more_utils=True)
    page.add_chart(line)

    page.render(csv_file[:-4] + "_日投票量分析汇总.html")
示例#21
0
def plotFoodRanging(list_y1, list_y2, list_y3, list_y4, list_y5, list_y6,
                    list_y7, list_y8, list_y9, list_y10, list_y11, list_y12):

    page = Page()

    line1 = Line("上海饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line1.add("口味", list_y1[0], list_y1[1], mark_point=["max", "min"])
    line1.add("环境", list_y1[0], list_y1[2], mark_point=["max", "min"])
    line1.add("服务", list_y1[0], list_y1[3], mark_point=["max", "min"])
    line1.add("综合", list_y1[0], list_y1[4], mark_point=["max", "min"])
    bar1 = Bar("上海饭店评分统计", "数据来源于大众点评TOP100")
    bar1.add("上海", list_y1[0][:10], list_y1[4][:10], mark_point=["max", "min"])
    wordcloud1 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud1.add("",
                   list_y1[0][:20],
                   list_y1[4][:20],
                   word_size_range=[20, 100])

    line2 = Line("北京饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line2.add("口味", list_y2[0], list_y2[1], mark_point=["max", "min"])
    line2.add("环境", list_y2[0], list_y2[2], mark_point=["max", "min"])
    line2.add("服务", list_y2[0], list_y2[3], mark_point=["max", "min"])
    line2.add("综合", list_y2[0], list_y2[4], mark_point=["max", "min"])
    bar2 = Bar("北京饭店评分统计", "数据来源于大众点评TOP100")
    bar2.add("北京", list_y2[0][:10], list_y2[4][:10], mark_point=["max", "min"])
    wordcloud2 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud2.add("",
                   list_y2[0][:20],
                   list_y2[4][:20],
                   word_size_range=[20, 100])

    line3 = Line("广州饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line3.add("口味", list_y3[0], list_y3[1], mark_point=["max", "min"])
    line3.add("环境", list_y3[0], list_y3[2], mark_point=["max", "min"])
    line3.add("服务", list_y3[0], list_y3[3], mark_point=["max", "min"])
    line3.add("综合", list_y3[0], list_y3[4], mark_point=["max", "min"])
    bar3 = Bar("广州饭店评分统计", "数据来源于大众点评TOP100")
    bar3.add("广州", list_y3[0][:10], list_y3[4][:10], mark_point=["max", "min"])
    wordcloud3 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud3.add("",
                   list_y3[0][:20],
                   list_y3[4][:20],
                   word_size_range=[20, 100])

    line4 = Line("深圳饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line4.add("口味", list_y4[0], list_y4[1], mark_point=["max", "min"])
    line4.add("环境", list_y4[0], list_y4[2], mark_point=["max", "min"])
    line4.add("服务", list_y4[0], list_y4[3], mark_point=["max", "min"])
    line4.add("综合", list_y4[0], list_y4[4], mark_point=["max", "min"])
    bar4 = Bar("深圳饭店评分统计", "数据来源于大众点评TOP100")
    bar4.add("深圳", list_y4[0][:10], list_y4[4][:10], mark_point=["max", "min"])
    wordcloud4 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud4.add("",
                   list_y4[0][:20],
                   list_y4[4][:20],
                   word_size_range=[20, 100])

    line5 = Line("天津饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line5.add("口味", list_y5[0], list_y5[1], mark_point=["max", "min"])
    line5.add("环境", list_y5[0], list_y5[2], mark_point=["max", "min"])
    line5.add("服务", list_y5[0], list_y5[3], mark_point=["max", "min"])
    bar5 = Bar("天津饭店评分统计", "数据来源于大众点评TOP100")
    bar5.add("天津", list_y5[0][:10], list_y5[4][:10], mark_point=["max", "min"])
    wordcloud5 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud5.add("",
                   list_y5[0][:20],
                   list_y5[4][:20],
                   word_size_range=[20, 100])

    line6 = Line("杭州饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line6.add("口味", list_y6[0], list_y6[1], mark_point=["max", "min"])
    line6.add("环境", list_y6[0], list_y6[2], mark_point=["max", "min"])
    line6.add("服务", list_y6[0], list_y6[3], mark_point=["max", "min"])
    line6.add("综合", list_y6[0], list_y6[4], mark_point=["max", "min"])
    bar6 = Bar("杭州饭店评分统计", "数据来源于大众点评TOP100")
    bar6.add("杭州", list_y6[0][:10], list_y6[4][:10], mark_point=["max", "min"])
    wordcloud6 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud6.add("",
                   list_y6[0][:20],
                   list_y6[4][:20],
                   word_size_range=[20, 100])

    line7 = Line("南京饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line7.add("口味", list_y7[0], list_y7[1], mark_point=["max", "min"])
    line7.add("环境", list_y7[0], list_y7[2], mark_point=["max", "min"])
    line7.add("服务", list_y7[0], list_y7[3], mark_point=["max", "min"])
    line7.add("综合", list_y7[0], list_y7[4], mark_point=["max", "min"])
    bar7 = Bar("南京饭店评分统计", "数据来源于大众点评TOP100")
    bar7.add("南京", list_y7[0][:10], list_y7[4][:10], mark_point=["max", "min"])
    wordcloud7 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud7.add("",
                   list_y7[0][:20],
                   list_y7[4][:20],
                   word_size_range=[20, 100])

    line8 = Line("苏州饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line8.add("口味", list_y8[0], list_y8[1], mark_point=["max", "min"])
    line8.add("环境", list_y8[0], list_y8[2], mark_point=["max", "min"])
    line8.add("服务", list_y8[0], list_y8[3], mark_point=["max", "min"])
    line8.add("综合", list_y8[0], list_y8[4], mark_point=["max", "min"])
    bar8 = Bar("苏州饭店评分统计", "数据来源于大众点评TOP100")
    bar8.add("苏州", list_y8[0][:10], list_y8[4][:10], mark_point=["max", "min"])
    wordcloud8 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud8.add("",
                   list_y8[0][:20],
                   list_y8[4][:20],
                   word_size_range=[20, 100])

    line9 = Line("成都饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line9.add("口味", list_y9[0], list_y9[1], mark_point=["max", "min"])
    line9.add("环境", list_y9[0], list_y9[2], mark_point=["max", "min"])
    line9.add("服务", list_y9[0], list_y9[3], mark_point=["max", "min"])
    line9.add("综合", list_y9[0], list_y9[4], mark_point=["max", "min"])
    bar9 = Bar("成都饭店评分统计", "数据来源于大众点评TOP100")
    bar9.add("成都", list_y9[0][:10], list_y9[4][:10], mark_point=["max", "min"])
    wordcloud9 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud9.add("",
                   list_y9[0][:20],
                   list_y9[4][:20],
                   word_size_range=[20, 100])

    line10 = Line("武汉饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line10.add("口味", list_y10[0], list_y10[1], mark_point=["max", "min"])
    line10.add("环境", list_y10[0], list_y10[2], mark_point=["max", "min"])
    line10.add("服务", list_y10[0], list_y10[3], mark_point=["max", "min"])
    line10.add("综合", list_y10[0], list_y10[4], mark_point=["max", "min"])
    bar10 = Bar("武汉饭店评分统计", "数据来源于大众点评TOP100")
    bar10.add("武汉",
              list_y10[0][:10],
              list_y10[4][:10],
              mark_point=["max", "min"])
    wordcloud10 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud10.add("",
                    list_y10[0][:20],
                    list_y10[4][:20],
                    word_size_range=[20, 100])

    line11 = Line("重庆饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line11.add("口味", list_y11[0], list_y11[1], mark_point=["max", "min"])
    line11.add("环境", list_y11[0], list_y11[2], mark_point=["max", "min"])
    line11.add("服务", list_y11[0], list_y11[3], mark_point=["max", "min"])
    line11.add("综合", list_y11[0], list_y11[4], mark_point=["max", "min"])
    bar11 = Bar("重庆饭店评分统计", "数据来源于大众点评TOP100")
    bar11.add("重庆",
              list_y11[0][:10],
              list_y11[4][:10],
              mark_point=["max", "min"])
    wordcloud11 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud11.add("",
                    list_y11[0][:20],
                    list_y11[4][:20],
                    word_size_range=[20, 100])

    line12 = Line("西安饭店评分统计", "数据来源于大众点评TOP100", width=1200)
    line12.add("口味", list_y12[0], list_y12[1], mark_point=["max", "min"])
    line12.add("环境", list_y12[0], list_y12[2], mark_point=["max", "min"])
    line12.add("服务", list_y12[0], list_y12[3], mark_point=["max", "min"])
    line12.add("综合", list_y12[0], list_y12[4], mark_point=["max", "min"])
    bar12 = Bar("西安饭店评分统计", "数据来源于大众点评TOP100")
    bar12.add("西安",
              list_y12[0][:10],
              list_y12[4][:10],
              mark_point=["max", "min"])
    wordcloud12 = WordCloud(width=1000, height=620, background_color="#EECFA1")
    wordcloud12.add("",
                    list_y12[0][:20],
                    list_y12[4][:20],
                    word_size_range=[20, 100])

    page.add(line1)
    page.add(wordcloud1)
    page.add(bar1)

    page.add(line2)
    page.add(wordcloud2)
    page.add(bar2)

    page.add(line3)
    page.add(wordcloud3)
    page.add(bar3)

    page.add(line4)
    page.add(wordcloud4)
    page.add(bar4)

    page.add(line5)
    page.add(wordcloud5)
    page.add(bar5)

    page.add(line6)
    page.add(wordcloud6)
    page.add(bar6)

    page.add(line7)
    page.add(wordcloud7)
    page.add(bar7)

    page.add(line8)
    page.add(wordcloud8)
    page.add(bar8)

    page.add(line9)
    page.add(wordcloud9)
    page.add(bar9)

    page.add(line10)
    page.add(wordcloud10)
    page.add(bar10)

    page.add(line11)
    page.add(wordcloud11)
    page.add(bar11)

    page.add(line12)
    page.add(wordcloud12)
    page.add(bar12)

    data1 = pd.DataFrame(list_y1[4][:10], list_y1[0][:10], ["综合值"])
    print(data1)
    data2 = pd.DataFrame(list_y2[4][:10], list_y2[0][:10], ["综合值"])
    print(data2)
    data3 = pd.DataFrame(list_y3[4][:10], list_y3[0][:10], ["综合值"])
    print(data3)
    data4 = pd.DataFrame(list_y4[4][:10], list_y4[0][:10], ["综合值"])
    print(data4)
    data5 = pd.DataFrame(list_y5[4][:10], list_y5[0][:10], ["综合值"])
    print(data5)
    data6 = pd.DataFrame(list_y6[4][:10], list_y6[0][:10], ["综合值"])
    print(data6)
    data7 = pd.DataFrame(list_y7[4][:10], list_y7[0][:10], ["综合值"])
    print(data7)
    data8 = pd.DataFrame(list_y8[4][:10], list_y8[0][:10], ["综合值"])
    print(data8)
    data9 = pd.DataFrame(list_y9[4][:10], list_y9[0][:10], ["综合值"])
    print(data9)
    data10 = pd.DataFrame(list_y10[4][:10], list_y10[0][:10], ["综合值"])
    print(data10)
    data11 = pd.DataFrame(list_y11[4][:10], list_y11[0][:10], ["综合值"])
    print(data11)
    data12 = pd.DataFrame(list_y12[4][:10], list_y12[0][:10], ["综合值"])
    print(data12)
    page.render("全部.html")
示例#22
0
import pandas as pd
from pyecharts import Bar

# 读取文件
df = pd.read_csv('douban.csv',
                 header=0,
                 names=["quote", "score", "info", "title", "people"])
# 清洗数据,获取电影年份,增加年份列
dom = []
for i in df['info']:
    dom.append(i.split('/')[0].replace('(中国大陆)', '').strip())
df['year'] = dom
# 计数排序
place_message = df.groupby(['year'])
place_com = place_message['year'].agg(['count'])
place_com.reset_index(inplace=True)
place_com_last = place_com.sort_index()
dom1 = place_com_last.sort_values('year', ascending=True)
# 生成柱状图
v1 = dom1['year']
attr = dom1['count']
bar = Bar("豆瓣电影TOP250-电影上映年份分布",
          title_pos='center',
          title_top='18',
          width=800,
          height=400)
bar.add("", v1, attr, is_label_show=True, is_datazoom_show=True)
bar.render('豆瓣电影TOP250上映年份分布.html')
commodity_x, sales_y, price_avg, price_y = [], [], [], []
# 筛选出前3品牌所有信息
[
    commodity_x.append(list(data[data['品牌'].isin([name[i]])]['名称'][:2]))
    for i in range(3)
]
[
    sales_y.append(list(data[data['品牌'].isin([name[j]])]['总评数'][:2]))
    for j in range(3)
]
[price_y.append(data[data['品牌'].isin([name[j]])]['名称']) for j in range(3)]
x = list(chain(*commodity_x))
sales = list(chain(*sales_y))
name_index = ['2S', 'pro', 'AC4076', 'AC4076/18', 'F-PDF35C-G', 'F-PXF35C-S']
for h in name_index:
    merchant = data[data['标题'].str.contains(h)]['价格']
    price_avg.append(sum(merchant) / len(merchant))
bar = Bar(width=1200, height=600)  #is_label_show=True  每根柱子显示值
bar.add('畅销型号销量',
        x,
        sales,
        line_color='green',
        is_label_show=True,
        xaxis_rotate=30)
line = Line()
line.add("平均价格", x, price_avg)
overlap = Overlap()
overlap.add(bar)
overlap.add(line, yaxis_index=1, is_add_yaxis=True)
overlap.render('3.2畅销产品和平均价格.html')
示例#24
0
from pyecharts import Bar

attr = ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar('标记线和标记示例')
bar.add('商家A', attr, v1, mark_line=['min', 'max'])  #标记点:商家A的平均值
bar.add('商家B', attr, v2, mark_line=['min', 'max'])  #标记线:商家B最小/最大值
bar.render('./picture4.html')
示例#25
0
import matplotlib.pyplot as plt 
from pyecharts import Geo,Style,Line,Bar,Overlap,Map, Pie


if __name__ == '__main__':
    conn = pymysql.connect(host="localhost",user="******",
    password="******",database="maoyan",port=3306,charset="utf8")
    cursor = conn.cursor()
    sql1 = "alter table moviecomment add column count_city int(40);"
    sql2 = """
    update moviecomment as m1 inner join
    (select city, count(*) as counting from moviecomment group by city) as m2
    on m1.city = m2.city set m1.count_city = m2.counting;
    """
    cursor.execute(sql1)
    cursor.execute(sql2)
    data = pd.read_sql("select * from moviecomment", conn) # 读取moviecomment中的数据
    cursor.close()
    conn.commit() 
    conn.close()
    cityData = data.groupby(['city','ranking','count_city']) # 将数据先按城市分类,再按评分分类
    citydata = cityData["id"].agg(["count"]) # 将分组后的数据的id进行叠加
    citydata.reset_index(inplace=True)  # 重置连续的index
    citydata['praise_rate'] = None
    citydata = citydata[~citydata['ranking'].isin([1.0, 2.0])]
    citydata['praise_rate'] = citydata.apply(lambda x: x['count'] / x['count_city'], axis=1)
    
    bar = Bar("各省好评率对比", width=1000,height=700)
    bar.add("百分比",citydata['city'],citydata['praise_rate'], is_convert=True,is_stack=True,xaxis_rotate=30,
    xaxis_interval=0,is_splitline_show=True,is_label_show=True)
    bar.render("D:\python_code\sample\猫眼\province_ranking.html")
示例#26
0
    '大大的三个字', '这里一共是十个字的吧', '这里一共是十个字的吧(这里是七个字)', '其他', '十全十美的十个字啊',
    'python仪表盘', '快乐三个字', '可乐续保三个字', '骑缝三个字', '里面好玩三个字', '信用卡三个字', '没空理我的',
    '订单问问三个字', '紫金学习三个字', '袋鼠妈妈三个字', '楼面价微信交流群', '密码三个字', '看见了来看看了解是是是',
    '大门口流量数据', '烤面筋解决三个字', '到读到蓝莓味'
]
# # 设置数据
data1 = [
    841, 0, 136, 0, 3317, 784, 1, 19, 691, 131, 21, 6461, 123, 0, 692, 0, 0, 0,
    0, 0, 0
]
data2 = [
    13056, 16614, 701, 0, 5815, 4274, 256, 689, 13838, 21723, 0, 16073, 28297,
    0, 279, 463, 25261, 60400, 0, 2493, 16
]
# # 设置柱状图的主标题与副标题
bar = Bar("这里是大标题", "这里上介绍文字", width=1200, height=600)


# # 添加柱状图的数据及配置项
def label_formatter(params):
    return str(params.value) + "\t\t"


bar.add("外网",
        columns,
        data1,
        bar_category_gap='10%',
        label_formatter=label_formatter,
        xaxis_label_textsize=6,
        grid_bottom=500,
        label_text_size=8,
示例#27
0
#!/usr/bin/Python
# -*- coding: utf-8 -*-
# @Date    : 2020-09-07
# Author   : flying

from pyecharts import Bar

# 绘制多个条形图
x_movies_name = ["猩球崛起", "敦刻尔克", "蜘蛛侠", "战狼2"]
y_16 = [15746, 312, 4497, 319]
y_15 = [12357, 156, 2045, 168]
y_14 = [2358, 399, 2358, 362]
bar2 = Bar(title="某年内地电影票房前20的电影", subtitle="子标题")
bar2.add('14号',x_movies_name,y_14)
bar2.add('15号',x_movies_name,y_15)
bar2.add('16号',x_movies_name,y_16)

bar2.render()


示例#28
0
for hotcomment in data['hotComments']:
    item = {
        'nickname':hotcomment['user']['nickname'],
        'content':hotcomment['content'],
        'likedCount':hotcomment['likedCount']
    }
    hotcomments.append(item)

#获取评论用户名,内容,以及对应的获赞数
content_list = [content['content'] for content in hotcomments]
nickname = [content['nickname'] for content in hotcomments]
liked_count = [content['likedCount'] for content in hotcomments]


from pyecharts import Bar

bar = Bar("热评中点赞数示例图")
bar.add( "点赞数",nickname, liked_count, is_stack=True,mark_line=["min", "max"],mark_point=["average"])
bar.render()


from wordcloud import WordCloud
import matplotlib.pyplot as plt

content_text = " ".join(content_list)
wordcloud = WordCloud(font_path=r"C:\simhei.ttf",max_words=200).generate(content_text)
plt.figure()
plt.imshow(wordcloud,interpolation='bilinear')
plt.axis('off')
plt.show()
示例#29
0
def test_bar_marks():
    bar = Bar("标记线和标记点示例")
    bar.add("商家A", CLOTHES, clothes_v1, mark_point=["average"])
    bar.add("商家B", CLOTHES, clothes_v2, mark_line=["min", "max"])
    assert '"average"' in bar._repr_html_()
示例#30
0
# 1. 柱状图
from pyecharts import Bar

bar = Bar("我的第一个图表", "Bar")

# 将3个关键字参数打包成1个数据类型为字典的变量kwargs。
kwargs = dict(name="柱状图",
              x_axis=["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
              y_axis=[5, 20, 6, 36, 10, 75])

# kwargs作为参数传入Bar对象的add方法中时,
# 需要使用**kwargs,这样可以使其自动解包,字典中的键值对会对应函数需要的参数。
bar.add(**kwargs)

# Bar对象的render方法会产生一个html文件,可以用浏览器打开该文件进行查看。
bar.render("bar01.html")

# 2. 直方图
# 在pyecharts中,直方图也是使用Bar对象画出。
# 与柱形图的不同之处是实例化Bar对象时多了1个参数bar_category_gap,
# 含义是每个柱子之间的间隔,如果设置为0,则画直方图。
bar = Bar("我的第二个图表", "Histogram")
kwargs = dict(name="直方图",
              x_axis=["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
              y_axis=[5, 20, 6, 36, 10, 75],
              bar_category_gap=0)
bar.add(**kwargs)
bar.render('Histogram.html')

# 3. 堆叠柱状图
x = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]