参考:https://www.cnblogs.com/zhizhan/p/5615947.html
通过matplotlib进行绘图:
例1:
import matplotlib.pyplot as plt labels='frogs','hogs','dogs','logs' sizes=15,20,45,10 colors='yellowgreen','gold','lightskyblue','lightcoral' explode=0,0.1,0,0 plt.pie(sizes,explode=explode,labels=labels,colors=colors,autopct='%1.1f%%',shadow=True,startangle=50) plt.axis('equal') plt.show()
例2:
from sklearn import datasets
import pandas as pd
import numpy as np import matplotlib.pyplot as plt iris=datasets.load_iris() name=iris.feature_names iris=pd.DataFrame(iris.data) iris.columns=name fig, axes = plt.subplots(2, 1) #设置2x1的图形格式 iris['sepal length (cm)'].hist(bins=100,ax=axes[0]) #bins用于指定条状图的个数 iris['sepal length (cm)']=np.log(iris['sepal length (cm)']) #对原数据取对数进行展示 iris['sepal length (cm)']=np.log1p(iris['sepal length (cm)']) #返回log(x+1)
iris['sepal length (cm)'].hist(bins=100,ax=axes[1]) plt.show()
iris['sepal length (cm)'].plot() #对所有数据点plot展示 plt.show()
设置中文字体和正负号:
import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['SimHei'] #用来正常显示中文标签 plt.rcParams['axes.unicode_minus']=False #用来正常显示负号