代码拉取完成,页面将自动刷新
import pandas as pd
from pyecharts.charts import * # pyecharts绘制图表
from pyecharts import options as opts
from pyecharts.commons.utils import JsCode
import math
import akshare as ak # 引入ak接口获取数据
# 获取实时数据信息
df_details = ak.fund_open_fund_daily_em()
# 获取基金历史数据
fund_open_fund_info_em_df = ak.fund_open_fund_info_em(fund="002810")
print(fund_open_fund_info_em_df)
# 获取基金经理的数据
manager_df = ak.fund_manager(adjust='0')
print(manager_df)
# 选择其中3个进行数据分析对比(股票型、股票指数型、混合型)
# 嘉实研究阿尔法股票 000082
# 银华中证等权重90指数 161816
# 招商安达灵活配置混合 217020
CODES = ['000082', '161816', '217020']
# 以股票型为例
df_times = ak.fund_open_fund_info_em(fund='000082')
# 将净值日期列转换为datetime类型
df_times['净值日期'] = pd.to_datetime(df_times['净值日期'])
# 绘制近一年、近六个月、近三个月的折线图
# 近一年
start = pd.datetime(2021,6,1)
end = df_times['净值日期'].max()
df_date = df_times[(df_times['净值日期']>=start) & (df_times['净值日期']<=end)]
data_x = [pd.to_datetime(x).strftime('%Y-%m-%d') for x in df_date['净值日期']]
days = len(data_x)
bg_color_js = """
new echarts.graphic.RadialGradient(0.3, 0.3, 0.8, [{
offset: 0,
color: '#f7f8fa'
}, {
offset: 1,
color: '#cdd0d5'
}])"""
line = Line(init_opts=opts.InitOpts(theme='light', bg_color=JsCode(bg_color_js), width='1000px', height='600px'))
line.add_xaxis(data_x)
for code in CODES:
money = 10000
df = ak.fund_open_fund_info_em(fund=code)
df['净值日期'] = pd.to_datetime(df['净值日期'])
df_final = df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
df_final = df[df['净值日期'].isin(data_x)]
name = df_details[df_details['基金代码']==code]['基金简称'].max()
data_y = []
for index, row in df_final.iterrows():
diff_rate = row['日增长率']
money = money + money * (diff_rate/100)
data_y.append(money/100-100)
if len(data_y) != days:
for index in range(days-len(data_y)):
data_y.insert(0, None)
line.add_yaxis(name,
data_y)
line.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
line.set_global_opts(yaxis_opts=opts.AxisOpts(name='涨跌/%', type_="value", is_scale=True,
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed')),
axislabel_opts=opts.LabelOpts(formatter='{value}%')),
xaxis_opts=opts.AxisOpts(name='日期',
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed'))),
legend_opts=opts.LegendOpts(is_show=True, pos_left=200, pos_top=100, orient='vertical', item_gap=20,
textstyle_opts=opts.TextStyleOpts(color='#fff', font_size=14, font_weight='bold')),
title_opts=opts.TitleOpts(title="基金走势对比[近一年]", pos_left='center',
title_textstyle_opts=opts.TextStyleOpts(color='black', font_size=20, font_weight='bold'),
subtitle='数据来源:akshare',
),
graphic_opts=[
opts.GraphicGroup(
graphic_item=opts.GraphicItem(id_='3',left="180px", top="80px"),
children=[
opts.GraphicRect(
graphic_item=opts.GraphicItem(
left="180px", top="80px", z=-1
),
graphic_shape_opts=opts.GraphicShapeOpts(
width=250, height=130
),
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
# 颜色配置,这里设置为黑色,透明度为0.5
fill="rgba(0,0,0,0.3)"
),
)
],
),]
)
line.render_notebook()
# 近六个月
start = pd.datetime(2022,1,1)
end = df_times['净值日期'].max()
df_date = df_times[(df_times['净值日期']>=start) & (df_times['净值日期']<=end)]
data_x = [pd.to_datetime(x).strftime('%Y-%m-%d') for x in df_date['净值日期']]
days = len(data_x)
bg_color_js = """
new echarts.graphic.RadialGradient(0.3, 0.3, 0.8, [{
offset: 0,
color: '#f7f8fa'
}, {
offset: 1,
color: '#cdd0d5'
}])"""
line = Line(init_opts=opts.InitOpts(theme='light', bg_color=JsCode(bg_color_js), width='1000px', height='600px'))
line.add_xaxis(data_x)
for code in CODES:
money = 10000
df = ak.fund_open_fund_info_em(fund=code)
df['净值日期'] = pd.to_datetime(df['净值日期'])
df_final = df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
df_final = df[df['净值日期'].isin(data_x)]
name = df_details[df_details['基金代码']==code]['基金简称'].max()
data_y = []
for index, row in df_final.iterrows():
diff_rate = row['日增长率']
money = money + money * (diff_rate/100)
data_y.append(money/100-100)
if len(data_y) != days:
for index in range(days-len(data_y)):
data_y.insert(0, None)
line.add_yaxis(name,
data_y)
line.set_series_opts(label_opts=opts.LabelOpts(is_show=False),)
line.set_global_opts(yaxis_opts=opts.AxisOpts(name='涨跌/%', type_="value", is_scale=True,
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed')),
axislabel_opts=opts.LabelOpts(formatter='{value}%')),
xaxis_opts=opts.AxisOpts(name='日期',
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed'))),
legend_opts=opts.LegendOpts(is_show=True, pos_left=200, pos_top=100, orient='vertical', item_gap=20,
textstyle_opts=opts.TextStyleOpts(color='#fff', font_size=14, font_weight='bold')),
title_opts=opts.TitleOpts(title="基金走势对比[近六个月]", pos_left='center',
title_textstyle_opts=opts.TextStyleOpts(color='black', font_size=20, font_weight='bold'),
subtitle='数据来源:akshare',
),
graphic_opts=[
opts.GraphicGroup(
graphic_item=opts.GraphicItem(id_='3',left="180px", top="80px"),
children=[
opts.GraphicRect(
graphic_item=opts.GraphicItem(
left="180px", top="80px", z=-1
),
graphic_shape_opts=opts.GraphicShapeOpts(
width=250, height=130
),
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
# 颜色配置,这里设置为黑色,透明度为0.5
fill="rgba(0,0,0,0.3)"
),
)
],
),]
)
line.render_notebook()
# 近三个月
start = pd.datetime(2022,3,1)
end = df_times['净值日期'].max()
df_date = df_times[(df_times['净值日期']>=start) & (df_times['净值日期']<=end)]
data_x = [pd.to_datetime(x).strftime('%Y-%m-%d') for x in df_date['净值日期']]
days = len(data_x)
bg_color_js = """
new echarts.graphic.RadialGradient(0.3, 0.3, 0.8, [{
offset: 0,
color: '#f7f8fa'
}, {
offset: 1,
color: '#cdd0d5'
}])"""
line = Line(init_opts=opts.InitOpts(theme='light', bg_color=JsCode(bg_color_js), width='1000px', height='600px'))
line.add_xaxis(data_x)
for code in CODES:
money = 10000
df = ak.fund_open_fund_info_em(fund=code)
df['净值日期'] = pd.to_datetime(df['净值日期'])
df_final = df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
df_final = df[df['净值日期'].isin(data_x)]
name = df_details[df_details['基金代码']==code]['基金简称'].max()
data_y = []
for index, row in df_final.iterrows():
diff_rate = row['日增长率']
money = money + money * (diff_rate/100)
data_y.append(money/100-100)
if len(data_y) != days:
for index in range(days-len(data_y)):
data_y.insert(0, None)
line.add_yaxis(name,
data_y)
line.set_series_opts(label_opts=opts.LabelOpts(is_show=False),)
line.set_global_opts(yaxis_opts=opts.AxisOpts(name='涨跌/%', type_="value", is_scale=True,
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed')),
axislabel_opts=opts.LabelOpts(formatter='{value}%')),
xaxis_opts=opts.AxisOpts(name='日期',
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed'))),
legend_opts=opts.LegendOpts(is_show=True, pos_left=200, pos_top=100, orient='vertical', item_gap=20,
textstyle_opts=opts.TextStyleOpts(color='#fff', font_size=14, font_weight='bold')),
title_opts=opts.TitleOpts(title="基金走势对比[近三个月]", pos_left='center',
title_textstyle_opts=opts.TextStyleOpts(color='black', font_size=20, font_weight='bold'),
subtitle='数据来源:akshare',
),
graphic_opts=[
opts.GraphicGroup(
graphic_item=opts.GraphicItem(id_='3',left="180px", top="80px"),
children=[
opts.GraphicRect(
graphic_item=opts.GraphicItem(
left="180px", top="80px", z=-1
),
graphic_shape_opts=opts.GraphicShapeOpts(
width=250, height=130
),
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
# 颜色配置,这里设置为黑色,透明度为0.5
fill="rgba(0,0,0,0.3)"
),
)
],
),]
)
line.render_notebook()
# 根据1w元本金的日收益图
# 嘉实研究阿尔法股票
# 1w元本金日收益图
start = pd.datetime(2022,1,1)
end = df_times['净值日期'].max()
df_date = df_times[(df_times['净值日期']>=start) & (df_times['净值日期']<=end)]
data_x = [pd.to_datetime(x).strftime('%Y-%m-%d') for x in df_date['净值日期']]
days = len(data_x)
df = pd.concat([df_times[df_times['净值日期'].isin(data_x)], ak.fund_open_fund_info_em(fund=CODES[0])], axis=1)
df_final = df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
name = df_details[df_details['基金代码']==CODES[0]]['基金简称'].max()
data_y_day, data_y_total = [], []
money = 10000
for _, row in df_final.iterrows():
diff_rate = row['日增长率'].max()
money = money + money * (diff_rate/100)
money_diff = money * (diff_rate/100)
data_y_day.append(int(money_diff))
data_y_total.append(money)
if len(data_y) != days:
for _ in range(days-len(data_y)):
data_y.insert(0, None)
bar = Bar(
init_opts=opts.InitOpts(
theme='white',
bg_color=JsCode(bg_color_js),
width='1200px',
height='800px'))
bar.add_xaxis(data_x)
bar.add_yaxis(name,
data_y_day, stack='1',
itemstyle_opts={"normal": {
'shadowBlur': 10,
'shadowColor': 'rgba(0, 0, 0, 0.5)',
'shadowOffsetX': 10,
'shadowOffsetY': 10,
# 'color':'red',
'borderColor': 'rgb(220,220,220)',
'borderWidth': 2}
},
gap='50%',
# bar_width=20,
tooltip_opts=opts.TooltipOpts(is_show=True, formatter='{b}<br>当日收益:{c}元'),
label_opts=opts.LabelOpts(is_show=False))
bar.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_show=False,
is_piecewise=True,
# dimension=0,
pieces=[{"max": 0, "color": 'green'},
{"min": 1,
"color": 'red'},
]),
yaxis_opts=opts.AxisOpts(name='日收益/元', type_="value", is_scale=True,
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed')),),
xaxis_opts=opts.AxisOpts(name='日期', # type_="time",
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed'))),
legend_opts=opts.LegendOpts(is_show=False),
)
line = Line(
init_opts=opts.InitOpts(
theme='white',
bg_color=JsCode(bg_color_js),
width='1200px',
height='800px'))
line.add_xaxis(data_x)
line.add_yaxis(name,
data_y_total,
is_symbol_show=True,
symbol='circle',
symbol_size=1,
is_smooth=True,
linestyle_opts={'shadowBlur': 5,
'shadowColor': 'rgba(0, 0, 0, 0.5)',
'shadowOffsetY': 10,
'shadowOffsetX': 10,
'width': 2,
'curve': 0.1,
# 'color': '#000000'
},
tooltip_opts=opts.TooltipOpts(is_show=False),
label_opts=opts.LabelOpts(is_show=False))
line.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_show=False,
is_piecewise=True,
# dimension=0,
pieces=[{"max": 0, "color": 'green'},
{"min": 1,
"color": 'red'},
]),
yaxis_opts=opts.AxisOpts(name='金额/元', type_="value", is_scale=True,
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed')),),
xaxis_opts=opts.AxisOpts(name='日期',
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed'))),
legend_opts=opts.LegendOpts(is_show=False),
title_opts=opts.TitleOpts(title="1W元本金日收益趋势", pos_left='center',
title_textstyle_opts=opts.TextStyleOpts(
color='black', font_size=20, font_weight='bold'),
subtitle='产品:{}'.format(name),
),
)
line.set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
markline_opts=opts.MarkLineOpts(
data=[
opts.MarkLineItem(type_="min", name="最小值"),
opts.MarkLineItem(type_="max", name="最大值"),
]
),
markpoint_opts=opts.MarkPointOpts(
data=[opts.MarkPointItem(name="收益", coord=[data_x[-1], data_y_total[-1]], value=int(data_y_total[-1]), symbol_size=[80,50])]
)
)
grid = Grid(
init_opts=opts.InitOpts(
theme='white',
bg_color=JsCode(bg_color_js),
width='1000px',
height='800px'))
grid.add(line, is_control_axis_index=False, grid_opts=opts.GridOpts(
pos_left='5%', pos_right='5%', pos_top='10%', pos_bottom='50%'))
grid.add(bar, is_control_axis_index=False, grid_opts=opts.GridOpts(
pos_left='5%', pos_right='5%', pos_top='60%', pos_bottom='5%'))
grid.render_notebook()
# 银华中证等权重90指数
# 1w元本金日收益图
start = pd.datetime(2022,1,1)
end = df_times['净值日期'].max()
df_date = df_times[(df_times['净值日期']>=start) & (df_times['净值日期']<=end)]
data_x = [pd.to_datetime(x).strftime('%Y-%m-%d') for x in df_date['净值日期']]
days = len(data_x)
df = pd.concat([df_times[df_times['净值日期'].isin(data_x)], ak.fund_open_fund_info_em(fund=CODES[1])], axis=1)
df_final = df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
name = df_details[df_details['基金代码']==CODES[1]]['基金简称'].max()
data_y_day, data_y_total = [], []
money = 10000
for _, row in df_final.iterrows():
diff_rate = row['日增长率'].max()
money = money + money * (diff_rate/100)
money_diff = money * (diff_rate/100)
data_y_day.append(int(money_diff))
data_y_total.append(money)
if len(data_y) != days:
for _ in range(days-len(data_y)):
data_y.insert(0, None)
bar = Bar(
init_opts=opts.InitOpts(
theme='white',
bg_color=JsCode(bg_color_js),
width='1200px',
height='800px'))
bar.add_xaxis(data_x)
bar.add_yaxis(name,
data_y_day, stack='1',
itemstyle_opts={"normal": {
'shadowBlur': 10,
'shadowColor': 'rgba(0, 0, 0, 0.5)',
'shadowOffsetX': 10,
'shadowOffsetY': 10,
# 'color':'red',
'borderColor': 'rgb(220,220,220)',
'borderWidth': 2}
},
gap='50%',
# bar_width=20,
tooltip_opts=opts.TooltipOpts(is_show=True, formatter='{b}<br>当日收益:{c}元'),
label_opts=opts.LabelOpts(is_show=False))
bar.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_show=False,
is_piecewise=True,
# dimension=0,
pieces=[{"max": 0, "color": 'green'},
{"min": 1,
"color": 'red'},
]),
yaxis_opts=opts.AxisOpts(name='日收益/元', type_="value", is_scale=True,
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed')),),
xaxis_opts=opts.AxisOpts(name='日期', # type_="time",
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed'))),
legend_opts=opts.LegendOpts(is_show=False),
)
line = Line(
init_opts=opts.InitOpts(
theme='white',
bg_color=JsCode(bg_color_js),
width='1200px',
height='800px'))
line.add_xaxis(data_x)
line.add_yaxis(name,
data_y_total,
is_symbol_show=True,
symbol='circle',
symbol_size=1,
is_smooth=True,
linestyle_opts={'shadowBlur': 5,
'shadowColor': 'rgba(0, 0, 0, 0.5)',
'shadowOffsetY': 10,
'shadowOffsetX': 10,
'width': 2,
'curve': 0.1,
# 'color': '#000000'
},
tooltip_opts=opts.TooltipOpts(is_show=False),
label_opts=opts.LabelOpts(is_show=False))
line.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_show=False,
is_piecewise=True,
# dimension=0,
pieces=[{"max": 0, "color": 'green'},
{"min": 1,
"color": 'red'},
]),
yaxis_opts=opts.AxisOpts(name='金额/元', type_="value", is_scale=True,
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed')),),
xaxis_opts=opts.AxisOpts(name='日期',
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed'))),
legend_opts=opts.LegendOpts(is_show=False),
title_opts=opts.TitleOpts(title="1W元本金日收益趋势", pos_left='center',
title_textstyle_opts=opts.TextStyleOpts(
color='black', font_size=20, font_weight='bold'),
subtitle='产品:{}'.format(name),
),
)
line.set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
markline_opts=opts.MarkLineOpts(
data=[
opts.MarkLineItem(type_="min", name="最小值"),
opts.MarkLineItem(type_="max", name="最大值"),
]
),
markpoint_opts=opts.MarkPointOpts(
data=[opts.MarkPointItem(name="收益", coord=[data_x[-1], data_y_total[-1]], value=int(data_y_total[-1]), symbol_size=[80,50])]
)
)
grid = Grid(
init_opts=opts.InitOpts(
theme='white',
bg_color=JsCode(bg_color_js),
width='1000px',
height='800px'))
grid.add(line, is_control_axis_index=False, grid_opts=opts.GridOpts(
pos_left='5%', pos_right='5%', pos_top='10%', pos_bottom='50%'))
grid.add(bar, is_control_axis_index=False, grid_opts=opts.GridOpts(
pos_left='5%', pos_right='5%', pos_top='60%', pos_bottom='5%'))
grid.render_notebook()
# 招商安达灵活配置混合
# 1w元本金日收益图
start = pd.datetime(2022,1,1)
end = df_times['净值日期'].max()
df_date = df_times[(df_times['净值日期']>=start) & (df_times['净值日期']<=end)]
data_x = [pd.to_datetime(x).strftime('%Y-%m-%d') for x in df_date['净值日期']]
days = len(data_x)
df = pd.concat([df_times[df_times['净值日期'].isin(data_x)], ak.fund_open_fund_info_em(fund=CODES[2])], axis=1)
df_final = df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
name = df_details[df_details['基金代码']==CODES[2]]['基金简称'].max()
data_y_day, data_y_total = [], []
money = 10000
for _, row in df_final.iterrows():
diff_rate = row['日增长率'].max()
money = money + money * (diff_rate/100)
money_diff = money * (diff_rate/100)
data_y_day.append(int(money_diff))
data_y_total.append(money)
if len(data_y) != days:
for _ in range(days-len(data_y)):
data_y.insert(0, None)
bar = Bar(
init_opts=opts.InitOpts(
theme='white',
bg_color=JsCode(bg_color_js),
width='1200px',
height='800px'))
bar.add_xaxis(data_x)
bar.add_yaxis(name,
data_y_day, stack='1',
itemstyle_opts={"normal": {
'shadowBlur': 10,
'shadowColor': 'rgba(0, 0, 0, 0.5)',
'shadowOffsetX': 10,
'shadowOffsetY': 10,
# 'color':'red',
'borderColor': 'rgb(220,220,220)',
'borderWidth': 2}
},
gap='50%',
# bar_width=20,
tooltip_opts=opts.TooltipOpts(is_show=True, formatter='{b}<br>当日收益:{c}元'),
label_opts=opts.LabelOpts(is_show=False))
bar.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_show=False,
is_piecewise=True,
# dimension=0,
pieces=[{"max": 0, "color": 'green'},
{"min": 1,
"color": 'red'},
]),
yaxis_opts=opts.AxisOpts(name='日收益/元', type_="value", is_scale=True,
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed')),),
xaxis_opts=opts.AxisOpts(name='日期', # type_="time",
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed'))),
legend_opts=opts.LegendOpts(is_show=False),
)
line = Line(
init_opts=opts.InitOpts(
theme='white',
bg_color=JsCode(bg_color_js),
width='1200px',
height='800px'))
line.add_xaxis(data_x)
line.add_yaxis(name,
data_y_total,
is_symbol_show=True,
symbol='circle',
symbol_size=1,
is_smooth=True,
linestyle_opts={'shadowBlur': 5,
'shadowColor': 'rgba(0, 0, 0, 0.5)',
'shadowOffsetY': 10,
'shadowOffsetX': 10,
'width': 2,
'curve': 0.1,
# 'color': '#000000'
},
tooltip_opts=opts.TooltipOpts(is_show=False),
label_opts=opts.LabelOpts(is_show=False))
line.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_show=False,
is_piecewise=True,
# dimension=0,
pieces=[{"max": 0, "color": 'green'},
{"min": 1,
"color": 'red'},
]),
yaxis_opts=opts.AxisOpts(name='金额/元', type_="value", is_scale=True,
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed')),),
xaxis_opts=opts.AxisOpts(name='日期',
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(type_='dashed'))),
legend_opts=opts.LegendOpts(is_show=False),
title_opts=opts.TitleOpts(title="1W元本金日收益趋势", pos_left='center',
title_textstyle_opts=opts.TextStyleOpts(
color='black', font_size=20, font_weight='bold'),
subtitle='产品:{}'.format(name),
),
)
line.set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
markline_opts=opts.MarkLineOpts(
data=[
opts.MarkLineItem(type_="min", name="最小值"),
opts.MarkLineItem(type_="max", name="最大值"),
]
),
markpoint_opts=opts.MarkPointOpts(
data=[opts.MarkPointItem(name="收益", coord=[data_x[-1], data_y_total[-1]], value=int(data_y_total[-1]), symbol_size=[80,50])]
)
)
grid = Grid(
init_opts=opts.InitOpts(
theme='white',
bg_color=JsCode(bg_color_js),
width='1000px',
height='800px'))
grid.add(line, is_control_axis_index=False, grid_opts=opts.GridOpts(
pos_left='5%', pos_right='5%', pos_top='10%', pos_bottom='50%'))
grid.add(bar, is_control_axis_index=False, grid_opts=opts.GridOpts(
pos_left='5%', pos_right='5%', pos_top='60%', pos_bottom='5%'))
grid.render_notebook()
# 基金经理从业经验分布图
days = manager_df['累计从业时间'].tolist()
years = []
for d in days:
year = math.ceil(d / 365)
years.append(year)
manager_df['累计从业时间(年)'] = manager_df.loc[:,('累计从业时间')] = years
manager_df['累计从业时间(离散)'] = pd.cut(
manager_df['累计从业时间(年)'], bins=[0, 1, 3, 5, 10, float('inf')],
labels=["1年以下", "1-3年", "3-5年", '5-10年', '10年以上']
)
data = dict(manager_df['累计从业时间(离散)'].value_counts())
pie = Pie(init_opts=opts.InitOpts(
theme='light',
width='1000px',
height='600px'
)
)
pie.add("",
[(k, int(v)) for k, v in data.items()],
radius=["40%", "75%"],
label_opts=opts.LabelOpts(is_show=True, formatter='{b}:{d}%'))
pie.set_global_opts(title_opts=opts.TitleOpts(
title="基金经理\n\n从业经验分布", pos_left='center', pos_top='center',
title_textstyle_opts=opts.TextStyleOpts(
color='black', font_size=24, font_weight='bold'
),
),
)
pie.render_notebook()
# 基金经理管理资产规模分布图
manager_df['现任基金资产总规模(离散)'] = pd.cut(manager_df['现任基金资产总规模'], bins=[0, 5, 20, 50, 100, 300, float('inf')],
labels=["5亿以下", "5-20亿", "20-50亿", '50-100亿', '100-300亿', '300亿以上'])
data = dict(manager_df['现任基金资产总规模(离散)'].value_counts())
pie = Pie(init_opts=opts.InitOpts(theme='light',
width='1000px',
height='600px'))
pie.add("",
[(k, int(v)) for k, v in data.items()],
radius=["40%", "75%"],
label_opts=opts.LabelOpts(is_show=True, formatter='{b}:{d}%'))
pie.set_global_opts(title_opts=opts.TitleOpts(
title="基金经理\n\n管理资产规模分布", pos_left='center', pos_top='center',
title_textstyle_opts=opts.TextStyleOpts(
color='black', font_size=24, font_weight='bold'),
),
)
pie.render_notebook()
# 最佳回报率
manager_df['现任基金最佳回报(离散)'] = pd.cut(manager_df['现任基金最佳回报'], bins=[-float('inf'), 0, 20, 50, 100, 200, float('inf')],
labels=["亏损", "0-20%", "20%-50%", '50%-100%', '100%-200%', '200%以上'])
data = dict(manager_df['现任基金最佳回报(离散)'].value_counts())
pie = Pie(init_opts=opts.InitOpts(theme='light',
width='1000px',
height='600px'))
pie.add("",
[(k, int(v)) for k, v in data.items()],
radius=["40%", "75%"],
label_opts=opts.LabelOpts(is_show=True, formatter='{b}:{d}%'))
pie.set_global_opts(title_opts=opts.TitleOpts(
title="基金经理\n\n管理基金最佳回报分布", pos_left='center', pos_top='center',
title_textstyle_opts=opts.TextStyleOpts(
color='black', font_size=22, font_weight='bold'),
),
)
pie.render_notebook()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。