为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 y 轴(matplotlob (P 2.7) 正确获得正确顺序

如何在 y 轴(matplotlob (P 2.7) 正确获得正确顺序

慕盖茨4494581 2021-07-14 18:15:39
我想知道为什么 y 轴的顺序是随机的(见截图)。我只是从带有值对的文本文件中绘制 x 和 y 值,并希望 y 轴从最小值开始并以最大值结束。在我的情况下,y 轴图的中间有最小的数字 (3)。我该如何纠正这个错误?txt文件:1,52,33,54,35,76,37,58,39,510,3代码:import matplotlib.pyplot as pltimport matplotlib.animation as animationfrom matplotlib import stylestyle.use('fivethirtyeight')fig = plt.figure()ax1 = fig.add_subplot(1,1,1)def animate(i):    graph_data = open('example.txt','r').read()    lines = graph_data.split('\n')    xs = []    ys = []    for line in lines:        if len(line) > 1:            x, y = line.split(',')            xs.append(x)            ys.append(y)    ax1.clear()    ax1.plot(xs, ys)ani = animation.FuncAnimation(fig, animate, interval=1000)  # 1000 ms = 1 sec (updating)plt.show()我发现编辑以下两行代码有帮助!!!之前: xs.append(x) ys.append(y)之后: xs.append(float(x)) ys.append(float(y))
查看完整描述

1 回答

?
BIG阳

TA贡献1859条经验 获得超6个赞

您在行上指定了 FiveThirtyEight 样式

style.use('fivethirtyeight')

只需将其删除即可使用正常的绘图样式。


查看完整回答
反对 回复 2021-07-28
  • 1 回答
  • 0 关注
  • 205 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号