网站描述设置,汕头网站搭建多少钱,wordpress 建网页,个人网站课程设计报告绘制瀑布图思路#xff1a;遍历指定文件目录下所有的csv文件#xff0c;每读一个文件#xff0c;取文件前20行数据进行保存#xff0c;如果超过规定的行数300行#xff0c;将最旧的数据删除#xff0c;仅保留300行数据进行展示。
网上找的大部分绘制瀑布图的代码#x…
绘制瀑布图思路遍历指定文件目录下所有的csv文件每读一个文件取文件前20行数据进行保存如果超过规定的行数300行将最旧的数据删除仅保留300行数据进行展示。
网上找的大部分绘制瀑布图的代码均无法呈现动态效果。不是动态的效果还能称为瀑布图吗(疑问)博主自己摸索了一套绘制动态图的思路这里全部代码贴出来如果需要绘制用的数据可以私信。当然也可以改代码以适用自己的数据。
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from matplotlib.animation import FuncAnimationfig, ax plt.subplots()
yLimLen 300
pastData np.ones((0, 0))def update(csvFilePathName):df pd.read_csv(csvFilePathName, header None)arr df.values[:10] global pastDataif not pastData.any():pastData arrelse:arr np.row_stack((pastData, arr))pastData arrlenNum arr.shape[0]print(flenNum:{lenNum})if lenNum yLimLen:arr arr[lenNum - yLimLen:-1]colors [greenyellow, yellow, darkblue, royalblue, orange, red]clrmap mcolors.LinearSegmentedColormap.from_list(mycmap, colors)csvFileName csvFilePathName.split(/)[2]ax.set_xlabel(csvFileName)plt.imshow(np.flipud(arr), cmap clrmap) #用于将数据反转最上面是最新的数据def configSet(drawUseFileNum 50):path r./2023-09-28_15/files os.listdir(path)[:drawUseFileNum]filePathName [path i for i in files]print(f一共有{len(files)}个文件)# fig, ax plt.subplots()ax.set_ylim(0, yLimLen)# ax.set_axis_off()ax.invert_yaxis()ani FuncAnimation(fig, update, frames filePathName, interval 50, blit False, repeat False)# plt.show()ani.save(move.gif, writerimagemagick)print(ffinish!)if __name__ __main__:configSet()