python可視化大屏-疫情監控圖(3)條形圖和面積圖


最終結果

數據准備

 

 導入的庫

from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType, SymbolType
from pyecharts.charts import Map
import pandas as pd
from pyecharts.charts import Bar
from pyecharts.globals import ThemeType

from pyecharts.charts import Map,Page

 

條形圖

data_votes = pd.read_excel(r'地域划分副本.xlsx')
# data_votes
# 數據排序,倒過來畫圖好看點
data_votes = data_votes.sort_values(by='出現次數',ascending=True)
# data_votes
# 數據結構重組
data_votes_x = data_votes['職稱'].tolist()
data_votes_y = data_votes['出現次數'].tolist()
# 畫條形圖
from pyecharts import options as opts
from pyecharts.charts import Bar

bar2 = (
    Bar(init_opts=opts.InitOpts(width='400px',height='300px',theme=ThemeType.DARK))
    .add_xaxis(data_votes_x)
    .add_yaxis("",
              data_votes_y
              )
    .reversal_axis() # 旋轉柱形圖方向
    .set_series_opts(label_opts=opts.LabelOpts(position="right")) # 設置數字標簽位置
    .set_global_opts(title_opts=opts.TitleOpts(title="《在一起》關鍵人物出現次數"),
                     visualmap_opts=opts.VisualMapOpts(
                                             max_= max(data_votes_y),
                                              min_= min(data_votes_y),
                                              range_color = ['#ffe100','#e82727'],
                                              pos_right='5%',
                                              pos_top='49%',
                                              dimension = 0, # 柱形圖需要加
                                             ),
                    )
)
bar2.render_notebook()

 

 結果

 

 面積圖

import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.globals import ThemeType
data = pd.read_excel(r'疫情華北華東西北新增趨勢 - 副本.xlsx')
x1 = data['日期'].agg(lambda x:str(x.day)).tolist()
y_data1 = data['北京']
y_data2 = data['甘肅']
y_data1
c2 = (
    Line(init_opts=opts.InitOpts(width='500px',height='400px',theme=ThemeType.DARK))
    .add_xaxis(x1)
    .add_yaxis(
        series_name="北京",
        stack="新增量",
        y_axis=y_data1,
        areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
        color='#FF8C69',
        is_smooth=True,   
    )
    
    .add_yaxis(
        series_name="甘肅",
        stack="新增量",
        y_axis=y_data2,
        areastyle_opts=opts.AreaStyleOpts(opacity=10),
        label_opts=opts.LabelOpts(is_show=False),
        color='#CD5C5C',
        is_smooth=True   
    )
    .set_global_opts(
        title_opts=opts.TitleOpts( title="北京甘肅新增區域圖"),
        tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
         xaxis_opts=opts.AxisOpts(type_="category",boundary_gap=False),
    )
    
)
c2.render_notebook()

結果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM