首页 > 编程知识 正文

python可视化库,Python 动态规划

时间:2023-05-06 00:43:18 阅读:138594 作者:4587

文章目录1、cufflinks介绍1.1概要1.2安装1.3 cufflinks软件包介绍1.4使用方法2、cufflinks, 2.0条形图bar 2.1直方图2.2 box箱型图2.3 scatter散点图2.4 lines线图2.5 bubble气泡图2.6 3d图2.7 scatter matrix散点图2.8 subplots子图2.9 shapes形状图3

3358 www.Sina.com/: https://pan.Baidu.com/s/1o5ukye 41i ao 9v _ cz HB s5ca

数据集和jupyter文件链接:by2a

一、cufflinks介绍了1.1的概要,学过Python数据分析的朋友都知道。 可视化的工具有很多优秀的三方库,如提取码matplotlibseaborn、http://www.Sina.com等。这些可视化库都有自己的特点

正如seaborn封装matplotlib一样,cufflinks在plotly的基础上进一步封装,方法统一,参数配置简单。 然后,您也可以自由地与pandas的dataframe配合使用进行绘制。 这可以被表达为'plotly'。

1.2 pipinstallcufflinks ' ' collectingcufflinksusingcached https://files.python hosted.org/packages/5e/5a/d3d 6523 ee 870 ECC 229008 b 209 b 6b 21231397302 de 34 f9c 446929 a 41 f 027/cuff links-0.16 . tar . gz ... successfullybuiltcufflinksretryinginstalling co llected packages: retrying,plotly,colorlover, cufflinkssuccessfullyinstalledcolorlover-0.3.0 cuff links-0.16 plot ly-3.10.0 retrying-1.3.3 ' ' 1.3 cuff links use'cufflinks.help(figure ) toseethelistofavailableparametersforthegivenfigure.use ' data frame.IP lot (kind=find ) ectivefigurefigures 3360 barboxbubblebubble3dcandlechoropletdistplotheatmaphistogramohlcpieratioscatterscatter 3d ceviolinnone 1.4 总结起来,其格式大致如下。

表示data frame.figure.iplotdataframe:pandas的数据框;

figure :表示上面的可绘制图形,例如bar、box、histogram等;

iplot )表示绘制方法,其中可以配置很多参数,调节适合自己风格的可视化图形;

二.如果cufflinks使用importpandasaspdimportnumpyasnpimportcufflinksascf #使用在线模式,则生成的图形受到限制。 因此,我们首先设定为offline模式,避免次数限制的问题。 cf.set _ config _ file (offline=true ) df=PD.read _ CSV ('./pimaindiansdiabetes.CSV ' ) print (df.shape ) 9 ) 2.0条形图bar#bar条形图df1=PD.data frame (NP.random.rand ) 12,4 ),columns=['a ',' b ',' c ',' d']df1

2.1随机生成histogram直方图histogram直方图cf.datagen.Histogram(3).IPlot ) kind='Histogram ' )

# Pima生成his

togram直方图df.iloc[:,0:3].iplot(kind='histogram') 2.2 box箱型图 # box箱型图,可以看到,x轴每个box都有对应的名称,这是因为cufflinks通过kind参数识别了box图形,# 自动为它生成的名字。如果我们只生成随机数,它是这样子的,默认生成100行的随机分布的数据,列数由自己选定。cf.datagen.box(20).iplot(kind='box',legend=False)

print(df.columns)'''Index(['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness', 'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age', 'Outcome'], dtype='object')'''df.iplot(kind='box',legend=False)

2.3 scatter散点图 # scatter散点图df.iplot(kind='scatter', mode='markers', colors=[ 'orange', 'teal', 'blue', 'yellow', 'black', 'red', 'green', 'magenta', 'cyan' ], size=5)

2.4 lines 线图 # 随机数绘图,'DataFrame' object has no attribute 'lines'cf.datagen.lines(1,500).ta_plot(study='sma',periods=[13,21,55])'''1)cufflinks使用datagen生成随机数;2)figure定义为lines形式,数据为(1,500);3)然后再用ta_plot绘制这一组时间序列,参数设置SMA展现三个不同周期的时序分析。

2.5 bubble气泡图 # bubble气泡图d = pd.DataFrame(np.random.rand(50, 4), columns=['a', 'b', 'c', 'd'])d.iplot(kind='bubble',x='a',y='b',size='a')

# bubble气泡图# pPma bubble气泡图d = df.iloc[0:100,:]#size决定了圈的大小d.iplot(kind='bubble',x='Glucose',y='DiabetesPedigreeFunction',size='DiabetesPedigreeFunction')

2.6 3d 图 #随机数生成3d 图cf.datagen.scatter3d(5,4).iplot(kind='scatter3d',x='x',y='y',z='z',text='text',categories='categories')

2.7 scatter matrix 散点矩阵图 #随机scatter matrix 散点矩阵图df2 = pd.DataFrame(np.random.randn(1000, 4), columns=['a', 'b', 'c', 'd'])df2.scatter_matrix()

#Pima scatter matrix 散点矩阵图df.iloc[0:200,0:5].scatter_matrix()

2.8 subplots 子图 #随机subplots 子图df3=cf.datagen.lines(4)df3.iplot(subplots=True,shape=(4,1),shared_xaxes=True,vertical_spacing=.02,fill=True)

#Pima subplots 子图df.iloc[0:200,0:5].iplot(subplots=True,shape=(5,1),shared_xaxes=True,vertical_spacing=.02,fill=True)

df.iloc[0:200,0:6].iplot(subplots=True,subplot_titles=True,legend=False)

2.9 shapes 形状图 # 随机shapes 形状图df5=cf.datagen.lines(3,columns=['a','b','c'])df5.iplot(hline=[dict(y=-1,color='blue',width=3),dict(y=1,color='pink',dash='dash')])# 将某个区域标记出来,可以使用hspan类型。竖条的区域,可以用vspan类型。df5.iplot(hspan=[(-1,1),(2,5)])

# Pima shapes 形状图df.iloc[0:200,0:6].iplot(hline=[dict(y=-1,color='blue',width=3),dict(y=1,color='pink',dash='dash')])# 将某个区域标记出来,可以使用hspan类型。竖条的区域,可以用vspan类型。df.iloc[0:200,0:6].iplot(hspan=[(100,120),(220,250)])


三、总结 help(df.iplot) 有趣的事,Python永远不会缺席

欢迎关注dmdzxc的博客

    文章内容来源于dmdzxc的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解

    如需转发,请注明出处:dmdzxc的博客python    https://www.cnblogs.com/xxtalhr/

博客园 https://www.cnblogs.com/xxtalhr/

CSDN https://blog.csdn.net/u010986753

有问题请在博客下留言或加作者:
     微信:tinghai87605025 联系我加微信群
     QQ :87605025
     python QQ交流群:py_data 483766429

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。