创新实训记录10---论文集合全体数据可视化嵌入

论文集合全体数据可视化

1.在初始页面加入论文集合全体数据可视化,如图:

在这里插入图片描述
在这里插入图片描述
2.整体效果:
在这里插入图片描述
在这里插入图片描述

代码:

1.index.html:

   <div class="panel panel-default">
                            <div class="panel-heading">
                                <h4 class="panel-title">
                                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
                                        数据集中不同年份的论文数量
                                    </a>
                                </h4>
                            </div>
                            <div id="collapseThree" class="panel-collapse collapse in"></div>
                                <div class="panel-body">
                                    <div id="graph_year_num" style="width:900px; height:500px;"></div>
                                   
                                
                                    </div>
                        </div>       
                                

                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h4 class="panel-title">
                                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
                                        不同年份论文的平均被引用量与引用量
                                    </a>
                                </h4>
                            </div>
                            <div id="collapseFour" class="panel-collapse collapse in"></div>
                                <div class="panel-body">
                                    <div id="graph_avg_txt" style="width:900px; height:500px;"></div>
                                   
                                    </div>
                        </div>   

<script>
//第一张柱形图
        var graph_year_num= {{ graph_year_num_txt | safe }};
            var chart_1 = echarts.init(
                document.getElementById('graph_year_num'), 'roma', { renderer: 'canvas' });
            var option_1 = graph_year_num
            chart_1.setOption(option_1);
        //第二张柱形图
        var graph_avg_txt= {{ graph_avg_txt | safe }};
            var chart_1 = echarts.init(
                document.getElementById('graph_avg_txt'), 'roma', { renderer: 'canvas' });
            var option_1 = graph_avg_txt
            chart_1.setOption(option_1);
    </script>      

2.view.py文件:

def index(request):  # 返回论文集合的论文标题
    paper_list = Paper.objects.all()
   
# 不同年份上论文集的个数(柱状图)-------------------------------------------
# 读取years.txt,将年份对应的论文数放入一个字典
    file_years = 'D:/code/django/display/choose_paper/data/years.txt'
    fyears = open(file_years, 'r')
    years_dic = {}
    for line in fyears:
        year = line.strip()
        if year in years_dic.keys() and year is not '':
            years_dic[year] += 1
        elif year is not '':
            temp = {}
            temp[year] = 1
            years_dic.update(temp)
        else:
            continue
    del years_dic['994']
    fyears.close()
# 构造x,y轴的数据
    x_data = []
    y_data = []
    for k in sorted(years_dic):
      x_data.append(k)
      y_data.append(years_dic[k])

    year_bar = Bar(init_opts=opts.InitOpts(width='1200px'))\
             .add_xaxis(xaxis_data = x_data)\
            .add_yaxis(series_name="论文数量",y_axis = y_data)
    year_bar.set_global_opts(title_opts=opts.TitleOpts(title='数据集中不同年份的论文数量'),
                         visualmap_opts=opts.VisualMapOpts(
    is_show=True,
    type_='color',
    is_piecewise=True,
    pieces=[
        {"min": 3000, "color": '#F01C06'},
        {"min": 2000, "max": 2999, "color": '#F93F2B'},
        {"min": 1000, "max": 1999, "color": '#FB8275'},
        {"min": 1000, "max": 1999, "color": '#FAA62A'},
        {"min": 500, "max": 999, "color": '#F4E362'},
        {"min": 100, "max": 499, "color": '#45F172'},
        {"min": 50, "max": 99, "color": '#7FC3F1'},
        {"max": 49, "color": '#C4E3F8'}
    ],
    orient='vertical'
))
    year_bar.render(path="choose_paper/data/graph/graph_year_num.txt")#显示图表
    graph_year_num_txt = "{"
    with open('choose_paper/data/graph/graph_year_num.txt', 'r', encoding='utf-8') as f:
        line = f.readlines()
        for i in range(15, len(line)-4):
            graph_year_num_txt += line[i]

#不同年份上论文集的平均引用量、被引用量(柱状图)------------------------------------------
    # 数据预处理:获取每篇论文的引用量
    #-----------------outlinks----------------------------
    olinkspath = 'D:/code/django/display/choose_paper/data/outlinks.txt'
    ofile = open(olinkspath,'r')
    outnum = []

    for line in ofile:
       lines = line.strip('\n').split()
       num = len(lines)
       outnum.append(num)
    ofile.close()
# 数据预处理:获取不同年份论文的总引用量
    file_years = 'D:/code/django/display/choose_paper/data/years.txt'
    fyears = open(file_years,'r')
    num_dic = { }
# 论文索引
    index = 0 

    for line in fyears:
      year = line.strip()
      if year in num_dic.keys() and year is not '':
        num_dic[year]+=outnum[index]
      elif year is not '':
        temp = {}
        temp[year] = outnum[index]
        num_dic.update(temp)
      else:
        index+=1
        continue
      index +=1

    del num_dic['994']
    fyears.close()
    # 构造x,y轴的数据
    x_data1 = []
    y_data1 = []
    for k in sorted(num_dic):
      x_data1.append(k)
      y_data1.append(num_dic[k])

# ----------------------------inlinks--------------------------------
    olinkspath = 'D:/code/django/display/choose_paper/data/inlinks.txt'
    ofile = open(olinkspath,'r')
    outnum = []

    for line in ofile:
       lines = line.strip('\n').split()
       num = len(lines)
       outnum.append(num)
    ofile.close()
# 数据预处理:获取不同年份论文的总引用量
    file_years = 'D:/code/django/display/choose_paper/data/years.txt'
    fyears = open(file_years,'r')
    num_dic = { }
# 论文索引
    index = 0 

    for line in fyears:
      year = line.strip()
      if year in num_dic.keys() and year is not '':
        num_dic[year]+=outnum[index]
      elif year is not '':
        temp = {}
        temp[year] = outnum[index]
        num_dic.update(temp)
      else:
        index+=1
        continue
      index +=1

    del num_dic['994']
    fyears.close()
    # 构造x,y轴的数据
    x_data2 = []
    y_data2= []
    for k in sorted(num_dic):
      x_data2.append(k)
      y_data2.append(num_dic[k])



    inavg_bar = Bar(init_opts=opts.InitOpts(width='1200px'))\
             .add_xaxis(xaxis_data = x_data2)\
            .add_yaxis(series_name="平均被引用量",y_axis = y_data2)\
            .add_yaxis(series_name="平均引用量",y_axis = y_data1)
    inavg_bar.set_global_opts(title_opts=opts.TitleOpts(title='不同年份论文的平均被引用量与引用量'),
                          datazoom_opts=opts.DataZoomOpts(is_show= True, 
                                                          orient="horizontal"))
    inavg_bar.render(path="choose_paper/data/graph/graph_avg.txt")#显示图表
    graph_avg_txt = "{"
    with open('choose_paper/data/graph/graph_avg.txt', 'r', encoding='utf-8') as f:
        line = f.readlines()
        for i in range(15, len(line)-4):
            graph_avg_txt += line[i]


    context = {
        'paper_list': paper_list,
        'graph_year_num_txt':graph_year_num_txt,
        'graph_avg_txt':graph_avg_txt
    }
    return render(request, 'choose_paper/index.html', context)

报错&解决:

1.Bar()柱状图调用报错:

add_yaxis() got an unexpected keyword argument 'yaxis_data'

在这里插入图片描述
解决: 重新复制粘贴并且重新打开项目即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值