【问题标题】:matplotlib not showing axis title and axis namesmatplotlib 不显示轴标题和轴名称
【发布时间】:2020-06-10 02:51:26
【问题描述】:

我正在尝试创建一个图表来使用 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')`

没有出现在剧情中

谁能帮忙?

【问题讨论】:

    标签: python matplotlib plot axis-labels


    【解决方案1】:

    您拨打ax1.clear() 会删除标签和标题。在调用命令后试试这个:

    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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 2020-03-27
      • 2017-08-12
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 1970-01-01
      相关资源
      最近更新 更多