首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >matplotlib不显示轴标题和轴名称

问matplotlib不显示轴标题和轴名称
EN

Stack Overflow用户
提问于 2020-06-10 10:51:27
回答 1查看 641关注 0票数 0

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

代码语言:javascript
复制
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()

我在上设置的轴名称和标题

代码语言:javascript
复制
ax1.xlabel('Days')
ax1.ylabel('Ads Posted')
ax1.title('Autoposter Performance')`

没有出现在图中

​

​

有人能帮上忙吗?

EN

回答 1

Stack Overflow用户

发布于 2020-06-10 11:00:08

您可以调用ax1.clear()来擦除标签和标题。在命令被调用后尝试这样做:

代码语言:javascript
复制
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
from matplotlib import style
import datetime
import numpy as np

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)

def animate(i):
    xar = np.arange(10)
    yar = np.arange(10)

    ax1.clear()
    ax1.set_xlabel('Days')
    ax1.set_ylabel('Ads Posted')
    ax1.set_title('Autoposter Performance')
    ax1.plot(xar,yar, color='purple', linewidth=0.125)

ani = animation.FuncAnimation(fig, animate, interval=1000)

plt.show()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62295030

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档