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()

 

采用子图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() #图形可视化

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值