首页 > 解决方案 > 如何在动画图上设置刻度位置?

问题描述

在下面的代码中,该图不使用我用 MultipleLocator 定义的刻度。我不知道为什么。我试图在 animate 函数中设置刻度位置,但它不起作用。

请 !有人可以告诉我如何解决这个问题

import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
import matplotlib.animation as animation

fig = plt.figure()
ax = fig.add_subplot(111)

ax.xaxis.set_major_locator(MultipleLocator(1))

ax.xaxis.set_major_locator(MultipleLocator(1))


def animate(i):
    f = open('data2.csv', 'r').read()
    lines = f.split('\n')
    x, y = [], []
    for line in lines:
        if len(line) > 1:
            a, b = line.split(';')
            x.append(float(a))

        y.append(float(b))
    ax.clear()
    ax.plot(x, y)


animation = animation.FuncAnimation(fig, animate, interval = 1000)
plt.show()

标签: pythonmatplotlibanimationticker

解决方案


推荐阅读