不同图像的绘制与保存
Scatterplot 散点图
data = sns.load_dataset("tips")
filepath = 'C:/Users'
fig_name = 'scatterplot.png'
# fig_path为想要存入的文件夹或地址
fig_path = filepath + '/' + fig_name
fig = sns.scatterplot(x = data['total_bill'], y = data['tip'], hue = 'time',
data = data, palette = 'Set1', s = 100)
scatter_fig = fig.get_figure()
scatter_fig.savefig(fig_path, dpi = 400)
Distplot 频率分布图
x = np.random.randn(100)
x = pd.Series(x, name = "x variable")
ax = sns.distplot(x)
hist_fig = ax.get_figure()
hist_fig.savefig(fig_path, dpi = 400)
Boxplot 箱型图
fig_dims = (7.5, 4)
fig, ax = plt.subplots(figsize=fig_dims)
fig = sns.boxplot(x = data['tip'], data = data, ax = ax, orient = "h", palette = "Set2")
plt.show()
boxplot = fig.get_figure()
boxplot.savefig(fig_path, dpi=400)
Heatmap 热力图
x = np.array([[1,2,3,4], [2,3,4,6], [10,2,3,6], [8,9,7,3]])
fig_name = 'heatmap.png'
fig_path = filepath + '/' + fig_name
fig = sns.heatmap(x, annot = True)
heatmap = fig.get_figure()
heatmap.savefig(fig_path, dpi = 400)
图像尺寸、间隙、分界线等调整,可查看👇
Pairplot 多变量图
iris = sns.load_dataset("iris")
pairplot_fig = sns.pairplot(iris, kind = 'scatter', hue="species", palette="Set2",
height=2.5, plot_kws=dict(s=50, alpha=0.4))
pairplot_fig.savefig(fig_path, dpi = 400)