matplotlib未显示轴标题和轴名称

问题描述 投票:0回答:1

我正在尝试创建一个图表以使用matplotlib绘制一些数据

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
from matplotlib import style
import datetime

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.xlabel('Days')
ax1.ylabel('Ads Posted')
ax1.title('Autoposter Performance')

def animate(i):
    pullData = open("data.txt","r").read()
    dataArray = pullData.split('\n')
    xar = []
    yar = []
    for eachLine in dataArray:
        if len(eachLine)>1:
            x,y = eachLine.split(',')
            xar.append(int(x))
            yar.append(int(y))
    ax1.clear()
    ax1.plot(xar,yar, color='purple', linewidth=0.125)
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()

我设置的轴名称和标题

ax1.xlabel('Days')
ax1.ylabel('Ads Posted')
ax1.title('Autoposter Performance')`

未显示在情节上

enter image description here

有人可以帮忙吗?

python matplotlib plot axis-labels
1个回答
0
投票

您呼叫ax1.clear(),这会删除标签和标题。尝试在调用命令后将其放入:

© www.soinside.com 2019 - 2024. All rights reserved.