可视化传播PythonCheatSheet (6).pdf

上传人:奉*** 文档编号:67735382 上传时间:2022-12-26 格式:PDF 页数:1 大小:623.97KB
返回 下载 相关 举报
可视化传播PythonCheatSheet (6).pdf_第1页
第1页 / 共1页
亲,该文档总共1页,全部预览完了,如果喜欢就下载吧!
资源描述

《可视化传播PythonCheatSheet (6).pdf》由会员分享,可在线阅读,更多相关《可视化传播PythonCheatSheet (6).pdf(1页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、Python For Data Science Cheat SheetSeabornLearn Data Science Interactively at www.DataC Statistical Data Visualization With SeabornDataCampLearn Python for Data Science Interactively Figure Aesthetics DataThe Python visualization library Seaborn is based on matplotlib and provides a high-level inter

2、face for drawing attractive statistical graphics.Make use of the following aliases to import the libraries:The basic steps to creating plots with Seaborn are:1.Prepare some data 2.Control figure aesthetics 3.Plot with Seaborn 4.Further customize your plot import pandas as pd import numpy as np unifo

3、rm_data=np.random.rand(10,12)data=pd.DataFrame(x:np.arange(1,101),y:np.random.normal(0,4,100)import matplotlib.pyplot as plt import seaborn as sns Plotting With Seaborn import matplotlib.pyplot as plt import seaborn as sns tips=sns.load_dataset(tips)sns.set_style(whitegrid)g=sns.lmplot(x=tip,y=total

4、_bill,data=tips,aspect=2)g=(g.set_axis_labels(Tip,Total bill(USD).set(xlim=(0,10),ylim=(0,100)plt.title(title)plt.show(g)Step 4Step 2Step 1Step 5Step 31 titanic=sns.load_dataset(titanic)iris=sns.load_dataset(iris)Seaborn also offers built-in data sets:23 Further Customizations4 Show or Save Plot sns

5、.set()(Re)set the seaborn default sns.set_style(whitegrid)Set the matplotlib parameters sns.set_style(ticks,Set the matplotlib parameters xtick.major.size:8,ytick.major.size:8)sns.axes_style(whitegrid)Return a dict of params or use with with to temporarily set the styleAxis Grids f,ax=plt.subplots(f

6、igsize=(5,6)Create a figure and one subplot plt.title(A Title)Add plot title plt.ylabel(Survived)Adjust the label of the y-axis plt.xlabel(Sex)Adjust the label of the x-axis plt.ylim(0,100)Adjust the limits of the y-axis plt.xlim(0,10)Adjust the limits of the x-axis plt.setp(ax,yticks=0,5)Adjust a p

7、lot property plt.tight_layout()Adjust subplot params plt.show()Show the plot plt.savefig(foo.png)Save the plot as a figure plt.savefig(foo.png,Save transparent figure transparent=True)sns.regplot(x=sepal_width,Plot data and a linear regression y=sepal_length,model fit data=iris,ax=ax)g.despine(left=

8、True)Remove left spine g.set_ylabels(Survived)Set the labels of the y-axis g.set_xticklabels(rotation=45)Set the tick labels for x g.set_axis_labels(Survived,Set the axis labels Sex)h.set(xlim=(0,5),Set the limit and ticks of the ylim=(0,5),x-and y-axis xticks=0,2.5,5,yticks=0,2.5,5)Close&Clear plt.

9、cla()Clear an axis plt.clf()Clear an entire figure plt.close()Close a window5Also see Lists,NumPy&PandasAlso see MatplotlibAlso see MatplotlibAlso see MatplotlibAlso see MatplotlibContext Functions sns.set_context(talk)Set context to talk sns.set_context(notebook,Set context to notebook,font_scale=1

10、.5,Scale font elements and rc=lines.linewidth:2.5)override param mappingSeaborn styles sns.set_palette(husl,3)Define the color palette sns.color_palette(husl)Use with with to temporarily set palette flatui=#9b59b6,#3498db,#95a5a6,#e74c3c,#34495e,#2ecc71 sns.set_palette(flatui)Set your own color pale

11、tteColor PalettePlotAxisgrid Objects g=sns.FacetGrid(titanic,Subplot grid for plotting conditional col=survived,relationships row=sex)g=g.map(plt.hist,age)sns.factorplot(x=pclass,Draw a categorical plot onto a y=survived,Facetgrid hue=sex,data=titanic)sns.lmplot(x=sepal_width,Plot data and regressio

12、n model fits y=sepal_length,across a FacetGrid hue=species,data=iris)Regression PlotsCategorical Plots Scatterplot sns.stripplot(x=species,Scatterplot with one y=petal_length,categorical variable data=iris)sns.swarmplot(x=species,Categorical scatterplot with y=petal_length,non-overlapping points dat

13、a=iris)Bar Chart sns.barplot(x=sex,Show point estimates and y=survived,confidence intervals with hue=class,scatterplot glyphs data=titanic)Count Plot sns.countplot(x=deck,Show count of observations data=titanic,palette=Greens_d)Point Plot sns.pointplot(x=class,Show point estimates and y=survived,con

14、fidence intervals as hue=sex,rectangular bars data=titanic,palette=male:g,female:m,markers=,o,linestyles=-,-)Boxplot sns.boxplot(x=alive,Boxplot y=age,hue=adult_male,data=titanic)sns.boxplot(data=iris,orient=h)Boxplot with wide-form data Violinplot sns.violinplot(x=age,Violin plot y=sex,hue=survived

15、,data=titanic)plot=sns.distplot(data.y,Plot univariate distribution kde=False,color=b)Distribution Plots h=sns.PairGrid(iris)Subplot grid for plotting pairwise h=h.map(plt.scatter)relationships sns.pairplot(iris)Plot pairwise bivariate distributions i=sns.JointGrid(x=x,Grid for bivariate plot with marginal y=y,univariate plots data=data)i=i.plot(sns.regplot,sns.distplot)sns.jointplot(sepal_length,Plot bivariate distribution sepal_width,data=iris,kind=kde)Matrix Plots sns.heatmap(uniform_data,vmin=0,vmax=1)Heatmap

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com