python - matplotlib 不显示轴标题和轴名称
问题描述
我正在尝试创建一个图表来使用 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')`
没有出现在情节上
谁能帮忙?
解决方案
您调用ax1.clear()
which 会删除标签和标题。在调用命令后尝试这样做:
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()
推荐阅读
- python - Trying to run Python using Reticulate giving a module not found error, but it is installed
- python - 使用 Azure Pipelines 为 Raspberry Pi 构建 Python 包
- instagram - 如何根据最新的 instagram api 规则获取 instagram 访问令牌?
- javascript - 需要使用 Vue 获取点击的元素“名称”
- authentication - Nuxt Auth doesn't work with Google strategie
- mysql - 忽略唯一约束 MySql 中的特定字符串
- ios - SwiftUI NavigationBar not disappearing while scrolling
- mysql - laravel迁移中外键添加约束错误
- angularjs - 量角器,登录过程后脚本超时
- java - Kafka 消费者轮询仅第二次获取消息