Learning content
using matplotlib, although the previous contents and learned the contents of data visualization,
but still have to learn the system matplotlib in pycharm inside using
focus
1. Scatter
import matplotlib.pyplot as plt#使用前插入matplotlib
plt.scatter(x=,y=,s=,c='',marker='',alpha=)
#散点图必须要有x,y轴,s代表面积,可以自己设置,c代表颜色,marker是显示的图标,alpha代表透明度
plt.show()#显示图像指令
2. Line Chart
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
a = np.linspace(-np.pi, np.pi, 1000)
b = np.sin(a)
plt.plot(a, b)
plt.show()#numpy自带sin和Π的数据
3. bar
a=[5,10,15,20]
b=[7,13,18,22]
c=np.arange(4)
bar_width=0.3
plt.bar(c+bar_width,height=a,width=bar_width,color='r')
plt.bar(c,height=b,width=bar_width,color='b')
plt.show()#两幅图一起画
a=[5,10,15,20]
b=[7,13,18,22]
c=np.arange(4)
bar_width=0.3
plt.bar(c,height=a,width=bar_width,bottom=b,color='r')
plt.bar(c,height=b,width=bar_width,color='b')
plt.show()#重叠画
4. histogram
difference bar
mn=10#均值
sigma=20#方差
x=mn+sigma*np.random.rand(1000)
plt.hist(x,bins=100,color='r')
plt.show()
#二维hist2d
mn=10
sigma=20
x=mn+sigma*np.random.randn(1000)
y=2*mn+0.8*sigma*np.random.randn(1000)
plt.hist2d(x,y,bins=100)
plt.show()
The pie chart
label = ['A', 'B', 'C', 'D']
num = [10, 20, 30, 40]
plt.axes(aspect=1) # 设置成正圆
explode = [0.1, 0.1, 0.1, 0.1]#设置远离圆心的距离
plt.pie(x=num, labels=label, autopect='%0.2f%%'explode=explode, shadow=True)
#设置阴影和距离,这里%0.2意味小数点后面两位,%%代表显示百分号
plt.show()
6. boxplot
data = np.random.normal(size=(1000, 4), loc=0, scale=1)
labels = ['a', 'b', 'c', 'd']
plt.boxplot(data,sym='X',whis=0.5,labels=labels)#错误值用X,上下分为距离为whis
plt.show()