【数据分析】:python:P2P金融数据指标分析

版权声明:转载请联系博主。 https://blog.csdn.net/sunyaowu315/article/details/82907637

python:P2P金融数据指标分析

# -*- coding: utf-8 -*-
"""
Created on Wed Jul  4 17:31:47 2018

@author: 孙正阳
"""
#@导入功能模块数据包
import numpy as np
import pandas as pd 
#import matplotlib.pyplot as plt
#plt.rcParams["font.sans-serif"] = ["SimHei"]
#plt.rcParams['axes.unicode_minus'] = False
import warnings 
warnings.filterwarnings('ignore')

import os
os.chdir('C:/Users/A3/Desktop/')
df= pd.read_excel('指标画图.xlsx',sheetname = 0,header = 0,index_col = [0])
data = pd.DataFrame(df)
#==============================================================================
# timeStamp = df['time']
# tm = time.strptime(timeStamp, '%Y-%m-%d %H:%M:%S')
# tm
# timeArray = time.localtime(timeStamp)
# otherStyleTime = time.strftime("%Y--%m--%d %H:%M:%S", timeArray)
# otherStyleTime   # 2013--10--10 23:40:00
#==============================================================================
from bokeh.plotting import figure,show,output_file 
from bokeh.models import ColumnDataSource
from bokeh.models import HoverTool
from bokeh.layouts import gridplot
from bokeh.models.annotations import Span
from bokeh.models.annotations import Label
#from bokeh.layouts import gridplot

#数据统计
source = ColumnDataSource(data)
time_lst = data.index.tolist()
#创建数据
output_file('weight_add.html') 
hover = HoverTool(tooltips = [('指标',"@整体首逾率")])
p = figure(
           plot_width = 1000,
           plot_height =450,
           title = '音速分期C~M1%指标走势',
           x_axis_label = '时间趋势', 
           y_axis_label = 'C~M1%', 
           x_range = time_lst,
           y_range = [0,0.3],
           tools = [hover,'pan,wheel_zoom,box_zoom,save,reset,help'],# 工具栏位置
           toolbar_location='above'    # 工具栏位置:"above","below","left","right")
           )

p.line(x = 'time',
       y = '整体首逾率',
       source = source,
       legend = 'C~M1%-时间线',
       line_width = 1,
       line_alpha = 0.8,
       line_color = 'black',
       line_dash = [10,4])
p.circle(x = 'time',
         y = '整体首逾率',
         source = source,
         size = 10,
         color = 'green',
         alpha = 0.8)
p.title.text_color = "white"  #颜色
p.title.text_font = "times"   #字体
p.title.text_font_style = "italic"  #风格
p.title.text_font_size= '18pt'
p.title.background_fill_color = "black"  #背景颜色

# 设置标题

p.outline_line_width = 5         # 边框线宽
p.outline_line_alpha = 0.3       # 边框线透明度
p.outline_line_color = "green"    # 边框线颜色

p.background_fill_color = "beige"    # 绘图空间背景颜色
p.background_fill_alpha = 0.5        # 绘图空间背景透明度

p.border_fill_color = "whitesmoke"    # 外边界背景颜色
p.min_border_left = 80                # 外边界背景 - 左边宽度
p.min_border_right = 80               # 外边界背景 - 右边宽度
p.min_border_top = 30                 # 外边界背景 - 上宽度
p.min_border_bottom = 10              # 外边界背景 - 下宽度
#设置边界背景

p.yaxis.axis_line_width = 2  #线宽
p.yaxis.axis_line_color = "red"  #轴线颜色
# 设置轴线
p.axis.minor_tick_in = 5      # 刻度往绘图区域内延伸长度
p.axis.minor_tick_out = 3   # 刻度往绘图区域外延伸长度
# 设置刻度
#p.yaxis.bounds = (86, 100)
# 设置轴线范围

p.xaxis.axis_label = "时间"
p.xaxis.axis_label_text_color = "#aa6666"
p.xaxis.axis_label_standoff = 30
# 设置标签名称、字体颜色、偏移距离

p.yaxis.axis_label = "C~M1%"
p.yaxis.axis_label_text_font_style = "italic"
# 设置标签名称、字体

p.yaxis.major_label_text_color = "orange"
p.yaxis.major_label_orientation = "vertical"
# 设置y轴线:标签、字体颜色、字体角度

p.xgrid.grid_line_color = None
# 颜色设置,None时则不显示

p.ygrid.grid_line_alpha = 0.2
p.ygrid.grid_line_dash = [6, 4]
# 设置透明度,虚线设置
# dash → 通过设置间隔来做虚线
# minor_line → 设置次轴线
p.xgrid.minor_grid_line_color = 'navy'
p.xgrid.minor_grid_line_alpha = 0.1
#p = gridplot([p])
p.grid.bounds = (-1, 1)
# 设置填充边界

p.legend.location = "top_left"
# 设置图例位置:"top_left"、"top_center"、"top_right" (the default)、"center_right"、"bottom_right"、"bottom_center"
# "bottom_left"、"center_left"、"center"

p.legend.orientation = "vertical"
# 设置图例排列方向:"vertical" (默认)or "horizontal"

p.legend.label_text_font = "times"
p.legend.label_text_font_style = "italic"  # 斜体
p.legend.label_text_color = "navy"
p.legend.label_text_font_size = '12pt'
# 设置图例:字体、风格、颜色、字体大小

p.legend.border_line_width = 2
p.legend.border_line_color = "navy"
p.legend.border_line_alpha = 0.5
# 设置图例外边线:宽度、颜色、透明度

p.legend.background_fill_color = "gray"
p.legend.background_fill_alpha = 0.2
# 设置图例背景:颜色、透明度

upper = Span(location=0.1,           # 设置位置,对应坐标值
             dimension='width',    # 设置方向,width为横向,height为纵向  
             line_color='firebrick',
             line_width=1,# 设置线颜色、线宽
             line_dash = [5,2])
p.add_layout(upper)
# 绘制辅助线1
lower = Span(location=0.05, 
             dimension='width', 
             line_color='olive', 
             line_width=1,
             line_dash = [5,2])
p.add_layout(lower)
# 绘制辅助线2

#==============================================================================
# label1 = Label(x=6, y=86,       # 标注注释位置
#               x_offset=12,    # x偏移,同理y_offset
#               text="跑了10km",      # 注释内容
#               text_font_size="12pt",    # 字体大小
#               border_line_color="green", 
#               background_fill_color="gray", 
#               background_fill_alpha = 0.5   # 背景线条颜色、背景颜色、透明度
#              )
# p.add_layout(label1)
# label2 = Label(x=7, y=87.5,       # 标注注释位置
#               x_offset=12,    # x偏移,同理y_offset
#               text="吃了不少高热量食物",      # 注释内容
#               text_font_size="12pt",    # 字体大小
#               border_line_color="red", 
#               background_fill_color="gray", 
#               background_fill_alpha = 0.5   # 背景线条颜色、背景颜色、透明度
#              )
# p.add_layout(label2)
# label3 = Label(x=11, y=86,       # 标注注释位置
#               x_offset=12,    # x偏移,同理y_offset
#               text="跑步5km",      # 注释内容
#               text_font_size="12pt",    # 字体大小
#               border_line_color="green", 
#               background_fill_color="gray", 
#               background_fill_alpha = 0.5   # 背景线条颜色、背景颜色、透明度
#              )
# p.add_layout(label3)
# label4 = Label(x=13, y=87,       # 标注注释位置
#               x_offset=12,    # x偏移,同理y_offset
#               text="晚餐大量进食",      # 注释内容
#               text_font_size="12pt",    # 字体大小
#               border_line_color="red", 
#               background_fill_color="gray", 
#               background_fill_alpha = 0.5   # 背景线条颜色、背景颜色、透明度
#              )
# p.add_layout(label4)
#==============================================================================
# 绘制注释


#p = gridplot([p])

show(p)               

print('finished!')


猜你喜欢

转载自blog.csdn.net/sunyaowu315/article/details/82907637