Python3 - seaborn, matplotlib, pandas: hist(), plot.scatter(),plot.box(), plot.hexbin(),... 有料

博主是在Jupyter Notebooks上进行练习。若想知道如何创建Jupyter Notebooks, 请点击这里查阅。

要想查阅pandas.DataFrame.plot文档,请点击这里

要想查阅matplotlib的colormap文档,请点击这里

这次使用两个dataset:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df1 = pd.read_csv('df1', index_col=0)
print(df1.head())

结果如下:
在这里插入图片描述

df2 = pd.read_csv('df2')
print(df2.head())

结果如下:
在这里插入图片描述
使用hist():

# hist(): in pyplot module of matplotlib library is used to plot a histogram
df1['A'].hist()

结果如何:
在这里插入图片描述
使用hist(), bins:

# # hist(): in pyplot module of matplotlib library is used to plot a histogram
# bins: This parameter is an optional parameter and it contains the integer or sequence or string.
df1[['A','B','C','D']].hist(bins=30)
plt.tight_layout()

df1['A'].hist(bins=30)

结果如下:
在这里插入图片描述
另外一种写法调用hist:

df1['A'].plot(kind='hist')

df1['A'].plot(kind='hist', bins=30)

# Draw one histogram of the DataFrame’s columns.
# DataFrame.plot.hist()
#    A histogram is a representation of the distribution of data. 
#    This function groups the values of all given Series in the DataFrame into bins and draws all bins in one matplotlib.axes.Axes. 
#    This is useful when the DataFrame’s Series are in a similar scale.
# bins: number of histogram bins to be used
df1['A'].plot.hist(bins=30)

df1['A'].plot.hist()

结果如下:
在这里插入图片描述
在这里插入图片描述

现在使用plot.area():

# Draw a stacked area plot.
# An area plot displays quantitative data visually. This function wraps the matplotlib area function.
df2.plot.area()

# alpha的值越小,越透明
df2.plot.area(alpha=0.2)

结果如下:
在这里插入图片描述
使用plot.bar():

# plot.bar():
#      Vertical bar plot.
#      A bar plot is a plot that presents categorical data with rectangular bars with lengths proportional to the values that they represent.
#      A bar plot shows comparisons among discrete categories. 
#      One axis of the plot shows the specific categories being compared, and the other axis represents a measured value.
df2.plot.bar()

df2.plot.bar(alpha=0.3)

结果如下:
在这里插入图片描述

df2.plot.bar(stacked=True)

df2.plot.bar(stacked=True,alpha=0.3)

结果如下:
在这里插入图片描述
现在使用df1的dataset:

df1

结果如下:
在这里插入图片描述
现在使用df1.plot.scatter():

df1.plot.scatter(x='A',y='B')

df1.plot.scatter(x='A',y='B',c='C')

df1.plot.scatter(x='A',y='B',s=df1['C']*10)

结果如下:
在这里插入图片描述
在这里插入图片描述
使用plot.line():

# Plot Series or DataFrame as lines.
# This function is useful to plot lines using DataFrame’s values as coordinates.
df1.plot.line(x='A',y='B')

结果如下:
在这里插入图片描述
使用plot.box():

# Make a box plot of the DataFrame columns.
# A box plot is a method for graphically depicting groups of numerical data through their quartiles. 
# The box extends from the Q1 to Q3 quartile values of the data, with a line at the median (Q2). 
# The whiskers extend from the edges of box to show the range of the data. 
# The position of the whiskers is set by default to 1.5*IQR (IQR = Q3 - Q1) from the edges of the box. 
# Outlier points are those past the end of the whiskers.
df2.plot.box()

结果如下:
在这里插入图片描述
创建新的DataFrame:

df = pd.DataFrame(np.random.rand(1000,2),columns=['a','b'])
df.head()

结果如下:
在这里插入图片描述

使用plot.hexbin():

# Generate a hexagonal binning plot.
# Generate a hexagonal binning plot of x versus y. If C is None (the default), 
# this is a histogram of the number of occurrences of the observations at (x[i], y[i]).
df.plot.hexbin(x='a',y='b')

df.plot.hexbin(x='a',y='b',gridsize=10)

# cmap: colormap
df.plot.hexbin(x='a',y='b',gridsize=10,cmap='coolwarm')

结果如下:
在这里插入图片描述
在这里插入图片描述
使用plot.kde() 和 plot.density():

# Generate Kernel Density Estimate plot using Gaussian kernels.
# In statistics, kernel density estimation (KDE) is a non-parametric way to estimate the probability density function (PDF) of a random variable. 
# This function uses Gaussian kernels and includes automatic bandwidth determination.
df2['a'].plot.kde()

# Generate Kernel Density Estimate plot using Gaussian kernels.
# In statistics, kernel density estimation (KDE) is a non-parametric way to estimate the probability density function (PDF) of a random variable. 
# This function uses Gaussian kernels and includes automatic bandwidth determination.
df2['a'].plot.density()

结果如下:
在这里插入图片描述

df2.plot.kde()

结果如下:
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
2021-03-26 20:54:33,596 - Model - INFO - Epoch 1 (1/200): 2021-03-26 20:57:40,380 - Model - INFO - Train Instance Accuracy: 0.571037 2021-03-26 20:58:16,623 - Model - INFO - Test Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Best Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Save model... 2021-03-26 20:58:16,623 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 20:58:16,698 - Model - INFO - Epoch 2 (2/200): 2021-03-26 21:01:26,685 - Model - INFO - Train Instance Accuracy: 0.727947 2021-03-26 21:02:03,642 - Model - INFO - Test Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Best Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Save model... 2021-03-26 21:02:03,643 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 21:02:03,746 - Model - INFO - Epoch 3 (3/200): 2021-03-26 21:05:15,349 - Model - INFO - Train Instance Accuracy: 0.781606 2021-03-26 21:05:51,538 - Model - INFO - Test Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,538 - Model - INFO - Best Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,539 - Model - INFO - Save model... 2021-03-26 21:05:51,539 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 我有类似于这样的一段txt文件,请你帮我写一段代码来可视化这些训练结果
02-06

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值