记下各个简易模板,方便ctrl+c和ctrl+v

子图:

import numpy as np
import matplotlib.pyplot as plt


x = np.array(range(1,9))
y = np.array([np.random.randint(1,11) for i in range(8)])

plt.subplot(2,2,1)
plt.plot(x,y,color="b",label="line")
plt.subplot(2,2,2)
plt.plot(x,y,"g",lw=10)
plt.subplot(2,2,3)
plt.plot(x,y,"b")
plt.subplot(2,2,4)
plt.plot(x,y,"g",lw=10)
plt.legend()
plt.show()

柱状图:

x = np.array(range(1,9))
y1 = np.array([np.random.randint(1,11) for i in range(8)])
y2 = np.array([np.random.randint(1,11) for i in range(8)])

plt.plot(x,y1,"g",lw=10)
plt.bar(x,y2,0.5,alpha=1,color="b")
plt.show()

  

dataframe生成图表

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt


df = pd.DataFrame(np.zeros((10,3)),columns=["c1","c2","c3"])

fig, axs = plt.subplots()
clust_data = df.values
collabel = df.columns
axs.axis('tight')
axs.axis('off')
the_table = axs.table(cellText=clust_data,colLabels=collabel,loc='center')
plt.show()