如何防止xaxis上的日期在MatPlotlib动画上拥挤

2024-10-04 09:21:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我成功地制作了我的第一张gif图形,但我仍然不知道如何解决越来越多的日期拥挤的问题。大约有365个日期轴

fig = plt.figure()
#df7.plot(x = 'DateOfStop')
plt.xticks(rotation=45, ha="right", rotation_mode="anchor")
plt.subplots_adjust(bottom = 0.2, top = 0.9)
plt.xlabel('Dates')
plt.ylabel('Stops')
plt.tight_layout()

def buildmebarchart(i=int):
    plt.plot( df7[:i].DateOfStop, df7[:i].cum_black, color ='red') 
    plt.plot( df7[:i].DateOfStop, df7[:i].cum_white, color ='blue') 
    plt.plot( df7[:i].DateOfStop, df7[:i].cum_Asian, color ='green')
    plt.plot( df7[:i].DateOfStop, df7[:i].cum_AmericanIndian, color ='orange') 
    plt.plot( df7[:i].DateOfStop, df7[:i].cum_Latinos, color ='purple')  
    plt.plot( df7[:i].DateOfStop, df7[:i].cum_PacificIslanders, color ='pink') 


animator = ani.FuncAnimation(fig,buildmebarchart, interval = 200)
#plt.show()
Writer = ani.writers['ffmpeg']
writer = Writer(fps=20, metadata=dict(artist='Me'), bitrate=1800)
animator.save('gif.mp4', writer = writer)

enter image description here


Tags: 图形plotfigpltgifcolorwriterrotation