matplotlib绘图,绘制多条线段

基本绘图:

import matplotlib.pyplot as plt
a=[0.005,0.01,0.02,0.04,0.06]
b=[20,18,10,13,15]
plt.plot(a,b)
plt.xlabel("初始位移量/mm")
plt.ylabel("迭代次数")
plt.show()

matplotlib绘图,绘制多条线段_第1张图片

 

采用子图subplots绘制多条线段:

import matplotlib.pyplot as plt
import numpy as np
a=[1,2,3]
b=[4,5,6]
c=[7,8,9]
x=[1,2,3]
#print([i+1 for i in a])
d=[]
d.append(a)
d.append(b)
d.append(c)
print(np.shape(d[0]))
for test in d:
    print(test)
fig, ax = plt.subplots() # 创建图实例
ax.plot(x, a, label='linear') # 作y1 = x 图,并标记此线名为linear

ax.plot(x, b, label='quadratic') #作y2 = x^2 图,并标记此线名为quadratic

ax.plot(x, d[2], label='cubic') # 作y3 = x^3 图,并标记此线名为cubic
ax.set_xlabel('x label') #设置x轴名称 x label
ax.set_ylabel('y label') #设置y轴名称 y label
ax.set_title('Simple Plot') #设置图名为Simple Plot
ax.legend() #自动检测要在图例中显示的元素,并且显示

plt.show() #图形可视化

matplotlib绘图,绘制多条线段_第2张图片

 

你可能感兴趣的:(python基础,matplotlib)