plotly图库

本文介绍了如何利用Plotly库生成详细的面积图,通过实例展示其步骤和关键代码,帮助理解如何在数据分析中运用面积图进行可视化。
摘要由CSDN通过智能技术生成

plotly

1.面积图

# 导入plotly库与离线库

import plotly as py
import plotly.graph_objs as go
import numpy as np

pyplt = py.offline.plot

# 随机生成np.array,先设置两个随机种子
random_state1 = np.random.RandomState(0)
random_state2 = np.random.RandomState(2)

# 随机生成100个数
num1 = random_state1.rand(100) / 10
num2 = random_state2.rand(100) / 10

print('num1:',num1)
print('num2:',num2)

# 设定初始基金价格
og1 = 10000
og2 = 10000

fund1 = []
fund2 = []
for i in list(range(100)):
    # 计算每一天的收益率
    og1 = og1 * num1[i] + og1
    og2 = og2 * num2[i] + og2
    # 统计每天收市之后的价格波动
    fund1.append(og1)
    fund2.append(og2)

trace1 = go.Scatter(
    y = fund1,
    fill = 'tonexty',
    mode = 'none', # 无边界线
    name = "基金一号"
)

trace2 = go.Scatter(
    y = fund2,
    fill = 'tonexty',
    mode = 'none', # 无边界线
    name = "基金二号"
)

data = [trace1, trace2]
layout = dict(title = '基金波动曲线',
              xaxis = dict(title = '交易天数'),
              yaxis = dict(title = '净值'),
              )
fig = dict(data = data, layout = layout)
pyplt(fig, filename = 'D:\基金波动曲线.html')

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值