python如何保持数据类型不变_python – matplotlib – 如何在添加新数据时保持轴不变?...

我正在使用matplotlib来显示不断更新的数据(每秒大约改变10次).我正在使用3D散点图,我希望将轴固定到特定范围,因为数据相对于绘图边缘的位置非常重要.

目前,每当我添加新数据时,轴将重置为按数据缩放,而不是我想要的大小(当我有hold = False时).如果我设置hold = True,轴将保持正确的大小,但新数据将叠加在旧数据上,这不是我想要的.

如果我每次获取新数据时重新调整轴,我都可以使用它,但这似乎是一种低效的方法,特别是因为我还需要再次执行所有其他格式化(添加标题,图例等)

有没有什么方法可以只指定一次图的属性,这将在我添加新数据时保持不变?

这是我的代码的大致轮廓,以帮助解释我的意思:

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

X_MAX = 50

Y_MAX = 50

Z_MAX = 50

fig = plt.figure(1)

ax = fig.add_subplot(111, projection='3d')

ax.set_title("My Title")

ax.set_xlim3d([0, X_MAX])

ax.set_ylim3d([0, Y_MAX])

ax.set_zlim3d([0, Z_MAX])

ax.set_autoscale_on(False)

# This is so the new data replaces the old data

# seems to be replacing the axis ranges as well, maybe a different method should be used?

ax.hold(False)

plt.ion()

plt.show()

a = 0

while a < 50:

a += 1

ax.scatter( a, a/2+1, 3, s=1 )

# If I don't set the title and axes ranges again here, they will be reset each time

# I want to know if there is a way to only set them once and have it persistent

ax.set_title("My Title")

ax.set_xlim3d([0, X_MAX])

ax.set_ylim3d([0, Y_MAX])

ax.set_zlim3d([0, Z_MAX])

plt.pause(0.001)

编辑:

我也尝试过ax.set_autoscale_on(False),但没有成功

我用常规的二维散点图试了这个,同样的问题依然存在

3.找到一个related question,但仍然没有答案

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值