python plotly 画饼状图

代码

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

path = ‘/home/v-gazh/PycharmProjects/us_data/limit_code.csv‘

df = pd.read_csv(path)
df.set_index([‘code‘], inplace=True)

# ST 占比
total_count = len(df)
st_count = len(df[df[‘isST‘]==1])
print(f‘禁投池总数:{total_count}‘)
print(f‘禁投池中ST个数:{st_count}‘)  # f‘禁投池中ST个数:{}‘

# 成分股占比
sz50_count = len(df[df[‘isSz50‘]==1])
print(f‘禁投池中上证50个数:{sz50_count}‘)
hs300_count = len(df[df[‘isHs300‘]==1])
print(f‘禁投池中沪深300个数:{hs300_count}‘)
zz500_count = len(df[df[‘isZz500‘]==1])
print(f‘禁投池中中证500个数:{zz500_count}‘)

# 退市占比
outdate_count = len(df[‘outDate‘].dropna())
print(f‘禁投池中退市股票个数:{outdate_count}‘)

# 非股票
not_stock = len(df[df[‘type‘]!=1])
print(f‘禁投池中非股票个数:{not_stock} 【SZ006415 为基金:F006415 | SZ000000 代码错误】‘)

# 次新股
delta_df = pd.DataFrame((pd.to_datetime(df[‘date‘]) - pd.to_datetime(df[‘ipoDate‘])))
new_stock = len(delta_df[delta_df[0] < pd.Timedelta(‘365 days‘)])  # 上市不满一年为次新股
print(f‘禁投池中次新股个数:{new_stock}‘)

# 市值小于30亿的股票
maketValue = len(df[df[‘maketValue‘] < 3000000000])
print(f‘市值小于30亿股票个数:{maketValue}‘)

# 画图
labels = [‘股票总数‘, ‘ST股票‘, ‘深证50‘, ‘沪深300‘, ‘中证500‘, ‘退市股票‘, ‘非股票‘, ‘次新股‘, ‘小市值‘]
values = [total_count, st_count, sz50_count, hs300_count, zz500_count, outdate_count, not_stock, new_stock, maketValue]

trace = go.Pie(labels=labels, values=values,textfont=dict(size=15),)
py.iplot([trace], filename=‘basic_pie_chart‘)

注:上面代码中,起主要作用的主要是

# 画图
labels = [‘股票总数‘, ‘ST股票‘, ‘深证50‘, ‘沪深300‘, ‘中证500‘, ‘退市股票‘, ‘非股票‘, ‘次新股‘, ‘小市值‘]
values = [total_count, st_count, sz50_count, hs300_count, zz500_count, outdate_count, not_stock, new_stock, maketValue]

trace = go.Pie(labels=labels, values=values,textfont=dict(size=15),)
py.iplot([trace], filename=‘basic_pie_chart‘)
values = [total_count, st_count, sz50_count, hs300_count, zz500_count, outdate_count, not_stock, new_stock, maketValue]

values 列表里的内容为int数值,对应上面的labels

图示

原文地址:https://www.cnblogs.com/bigtreei/p/12048151.html

时间: 2024-10-07 14:46:56

python plotly 画饼状图的相关文章

[控件] 画饼状图的控件

画饼状图的控件 效果 注意:支持遮罩效果 源码 https://github.com/YouXianMing/CircleView // // CircleView.h // YXMWeather // // Created by XianMingYou on 15/5/12. // Copyright (c) 2015年 XianMingYou. All rights reserved. // #import <UIKit/UIKit.h> @interface CircleView : U

Quartz2d 画饼状图 图形上下文栈 矩阵操作 裁剪圆角图片

画饼状图 - (void)drawRect:(CGRect)rect { // Drawing code // 需求:根据sections的数据,绘制多个扇形 // 1.获取上下文(Layer Graphics Context) CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.根据sections的个数,计算扇形的起始和结束位置来画扇形 NSInteger count = self.sections.count; // 如果没有数据,

canvas+js画饼状图

效果: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>饼状图</title> </head> <body> <canvas id="canvas"></canvas> <script> (function () {

[Python Study Notes]饼状图绘制

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' >>文件: 饼状图.py >>作者: liu yang >>邮箱: [email protected] >>博客: www.cnblogs.com/liu66blog '''''''''''''''''''''''''''''''''''''''''''''''

python的matplotlib饼状图

在python的matplotlib画图函数中,饼状图的函数为pie pie函数参数解读 plt.pie(x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=None, radius=None, counterclock=True, wedgeprops=None, textprops=None, center=(

HTML画饼状图

<!DOCTYPE HTML> <html> <head> <title>简单化饼图</title> <meta charset="utf-8"/> </head> <body> <canvas id="cav" width="800" height="800"> 对不起,您的浏览器版本过低,不支持HTML5. <

用canvas 画饼状图

<canvas id="cans"  height="800" width="1200" ></canvas> <script> function disToRad(n){ // 把角度转换为弧度 return n*Math.PI/180; //π用PI表示,π=180°,所以1°=PI/180 } window.onload=function(){ let cans=document.getElementBy

PHP画矩形,椭圆,圆,画椭圆弧 ,饼状图

1:画矩形: imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $col ) imagerectangle() 用 col 颜色在 image 图像中画一个矩形,其左上角坐标为 x1, y1,右下角坐标为 x2, y2.图像的左上角坐标为 0, 0. 2:画椭圆: imageellipse ( resource $image , int $cx , int $cy , int $width

python 饼状图

https://www.cnblogs.com/liming19680104/p/10614132.htmlimport pandas as pdimport numpy as npimport matplotlib.pyplot as plt #解决能显示中文plt.rcParams['font.sans-serif']=['SimHei'] #指定默认字体 SimHei为黑体plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 plt.titl