matplot 绘图
数据准备
import pandas as pd
idCardInfo = pd.read_csv("idcard.csv")
idCardInfo.head()
空图绘制
import matplotlib.pyplot as plt
plt.plot()
plt.show()
绘二维图
基础绘制
plt.plot(idCardInfo["confidence"],idCardInfo["money"])
plt.show()
完善图例
plt.plot(idCardInfo["confidence"],idCardInfo["money"])
plt.yticks(rotation=45)
plt.xticks(rotation=45)
plt.xlabel("confidence")
plt.ylabel("money")
plt.title("confidence - money")
plt.show()
绘制多图
多个空图
fig = plt.figure()
sf1 = fig.add_subplot(2,2,1)
sf2 = fig.add_subplot(2,2,2)
sf4 = fig.add_subplot(2,2,4)
plt.show()
多个二维图
fig = plt.figure()
sf1 = fig.add_subplot(2,2,1)
sf2 = fig.add_subplot(2,2,4)
sf1.plot(idCardInfo["money"],idCardInfo["confidence"],c='red')
sf2.plot(idCardInfo["confidence"],idCardInfo["money"])
plt.show()
多数据图
import numpy as np
fig = plt.figure(figsize=(16,6))
colors = ['red', 'blue', 'green', 'orange', 'black']
h = np.arange(10,100,10)
for i in range(5):
v = 1000*i + np.random.randn(9,1) * 1000
plt.plot(h, v, c=colors[i],label=label)
plt.legend(loc='best')
plt.show()
特殊图像
data = np.random.randn(2, 100)
fig, axs = plt.subplots(2, 2, figsize=(10, 10))
axs[0, 0].hist(data[0])
axs[1, 0].scatter(data[0], data[1])
axs[0, 1].plot(data[0], data[1])
axs[1, 1].hist2d(data[0], data[1])
plt.show()