条形图
1.plt.bar(list, list) 或者 plt.bar(list, Series)
2.pandas.Series.plot(kind='bar')
3.pandas.DataFrame.plot(kind='bar')
import matplotlib.pyplot as plt
import pandas as pddata_train = pd.read_csv('data/train.csv').head(5)plt.subplot2grid((2, 2), (0, 0))
plt.bar(list(data_train.Survived.index), data_train.Survived, width=0.2)
plt.title('plt.bar(list, list)')plt.subplot2grid((2, 2), (0, 1))
plt.bar(data_train.Survived, data_train.Age, width=0.2)
plt.title('plt.bar(list, list)')plt.subplot2grid((2, 2), (1, 0))
data_train['Survived'].plot(kind='bar', width=0.2)
plt.title('pandas.Series.plot(kind=\'bar\')')plt.subplot2grid((2, 2), (1, 1), colspan=1)
data_train[['Survived', 'Age']].plot(kind='bar', width=0.2)
plt.title('pandas.DataFrame.plot(kind=\'bar\')')plt.show()
散点图
1.plt.scatter(x=list, y=list)
2.DataFrame.plot(kind='scatter', x=list, y=list)
import matplotlib.pyplot as plt
import pandas as pddata_train = pd.read_csv('data/train.csv').head(5)plt.subplot2grid((1, 2), (0, 0))
plt.scatter(data_train.Survived, data_train.Age)
plt.title('plt.scatter(x=list, y=list)')plt.subplot2grid((1, 2), (0, 1))
data_train.plot(kind='scatter', x='Survived', y='Age')
plt.title('DataFrame.plot(kind=\'scatter\', list, list)')plt.show()
概率密度图
1.Series.plot(kind='kde')
import matplotlib.pyplot as plt
import pandas as pdplt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签data_train = pd.read_csv('data/train.csv')
data_train.Age.plot(kind='kde')
plt.title('Age 概率密度图')
plt.show()