先从网站下载数据集http://www.knapdata.com/python/,
ucdavis.csv
1、散点图
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style('darkgrid')#设置风格为暗,要不然看不出来
student=pd.read_csv("E:\chorme download\\ucdavis.csv")#下到电脑里自己设置下地址
g=sns.FacetGrid(student,col_order='class',size=7)#size为设置显示界面大小
g.map(plt.scatter,'momheight','height',s=140,linewidth=.7,edgecolor='red',color='#ff8000')#edgecolor为全边颜色,color为圈内颜色
g.set_axis_labels('Mothers height','student height')#设置标题
plt.show()
image.png
2、气泡图
···
st=pd.read_csv("E:\chorme download\ucdavis.csv")
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(st['momheight'], st['height'], s=st['exercise']) # 第三个变量为气泡大小
ax.set_xlabel('momheight')
ax.set_ylabel('height')
plt.show()
···
3、KDE图
from numpy.random import randn
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib as mpl
sns.set_style('darkgrid')
data=randn(250)
plt.title("KDE")
fontsize=10#x轴间距
sns.distplot(data,color='#ff8000')
plt.show()
image.png
网友评论