matplotlib01

 x and y must have same first dimension, but have shapes (119,) and (120,)

解决方法:保证维度相同

import random
from matplotlib import pyplot as plt
# x表示时间120分钟
x = range(1,120)   此处修改为121
y = [random.randint(20,35) for i in range(120)]
plt.figure(figsize=(20,8),dpi=80)

plt.plot(x,y)
plt.savefig("pract2.png")
plt.show()
x = range(1,121)
y = [random.randint(20,35) for i in range(120)]  xy维度保持一致


from matplotlib import pyplot as plt
import random
import matplotlib
from matplotlib import font_manager
f1=font_manager.FontProperties(fname=r"C:/Windows/Fonts/simsun.ttc")
y_1 = [1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
y_2 = [1,0,3,1,2,2,3,3,2,1 ,2,1,1,1,1,1,1,1,1,1]

x = range(11,31)

#设置图形大小
plt.figure(figsize=(20,8),dpi=80)

plt.plot(x,y_1,label="自己",color="#F08080")
plt.plot(x,y_2,label="同桌",color="#DB7093",linestyle="--")
_x=list(x)
x_label=["{}岁".format(i) for i in range(11,31)]
plt.xticks(_x,x_label,rotation=45,fontproperties=f1)
plt.yticks(range(0,9))
plt.grid(alpha=0.5)
plt.legend(prop=f1,loc="upper left")
plt.show()

展示图像

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值