python plotly绘制直方图实例详解

yipeiwu_com5年前Python基础

计算数值出现的次数

import cufflinks as cf
cf.go_offline()
import numpy as np
import pandas as pd

set_slippage_avg_cost = [22.01, 20.98, 17.11, 9.06, 9.4, 3.65, 19.65, 7.01, 11.21, 10.3, 5.1, 23.98, 12.03, 8.13, 8.07, 9.28, 3.93, 4.23, 18.6, 8.22, 7.85, 5.39, 29.4, 43.96, 6.12, 15.03, 2.68, 14.25, 7.9, 2.22, 15.74, 8.83, 8.18, 7.21, 30.38,25.46, 8.53, 8.05, 11.04, 24.95, 5.19, 6.8, 8.19, 5.44, 21.05, 7.06, 6.67, 18.61, 5.44, 2.9]

no_slippage_avg_cost = [22.04,21.01,17.13,9.07,9.41,3.65,19.67,7.02,11.22,10.31,5.11,24.01,12.04,8.14,8.08,9.29,3.93,4.24,18.62,8.23,7.86,5.4,29.44,44.01,6.13,15.05,2.68,14.27,7.91,2.22, 15.76, 8.84, 8.19, 7.22, 30.42, 25.49, 8.54, 8.06, 11.05, 24.98, 5.2, 6.81, 8.2, 5.45, 21.08, 7.07, 6.68,18.63,5.45,2.9]

diff = (np.array(no_slippage_avg_cost) - np.array(set_slippage_avg_cost)) / np.array(set_slippage_avg_cost)

pd.Series(diff).iplot(kind='histogram', bins=100, title='(np.array(no_slippage_avg_cost) - np.array(set_slippage_avg_cost)) / np.array(set_slippage_avg_cost)')

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python输出当前目录下index.html文件路径的方法

本文实例讲述了python输出当前目录下index.html文件路径的方法。分享给大家供大家参考。具体实现方法如下: import os import sys path = os.p...

使用Pytorch来拟合函数方式

其实各大深度学习框架背后的原理都可以理解为拟合一个参数数量特别庞大的函数,所以各框架都能用来拟合任意函数,Pytorch也能。 在这篇博客中,就以拟合y = ax + b为例(a和b为需...

python2.7无法使用pip的解决方法(安装easy_install)

1、 在Python IDLE下,我们输入以下代码 from urllib import urlopen【回车】 data = urlopen('http://peak.teleco...

Python实现线性判别分析(LDA)的MATLAB方式

Python实现线性判别分析(LDA)的MATLAB方式

线性判别分析(linear discriminant analysis),LDA。也称为Fisher线性判别(FLD)是模式识别的经典算法。 (1)中心思想:将高维的样本投影到最佳鉴别矢...

python3中str(字符串)的使用教程

本文主要介绍的是python3中对str(字符串)的使用操作总结,文中介绍的非常详细,需要的朋友们下面来一起看看吧。 __add__函数 (在后面追加字符串) s1 ='Hello'...