我运行了这个程序。出于某种原因,我没有得到所有的X轴值。试图改变数据仍然没有打印。
import matplotlib.pyplot as plt
import pandas as pd
import tkinter as tk
import pandas as pd
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import matplotlib.animation as animation
from pandas import Timestamp
import sys
if sys.version_info[0] < 3:
import Tkinter as Tk
else:
import tkinter as Tk
root = Tk.Tk()
top = Tk.Frame(root)
top.pack()
bottom = Tk.Frame(root)
bottom.pack()
fig = plt.Figure()
canvas = FigureCanvasTkAgg(fig, top)
canvas.get_tk_widget().pack()
canvas._tkcanvas.pack()
df = pd.read_csv("../data.csv")
ax = fig.add_subplot(111)
fig.suptitle('App Server CPU%', fontsize=12)
df['date'] = pd.to_datetime(df['date'], format='%Y/%m/%d %H:%M:%S')
df = df.set_index('date')
grouped = df.groupby(['server'])
for key, group in grouped:
group['utilization'].plot(label=key, ax=ax)
plt.legend(loc='best')
def on_closing():
#if messagebox.askokcancel("Quit", "Do you want to quit?"):
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_closing)
root.lift()
root.attributes('-topmost',True)
root.mainloop()
date,server,utilization
2004-08-19,App1,105.01
2004-08-20,App1,106.06
2004-08-23,App1,116.3
2004-08-24,App1,116.8
2004-08-25,App1,110
2004-08-26,App1,110.2
2004-08-27,App1,113.51
2004-08-19,App2,126.01
2004-08-20,App2,127.27
2004-08-23,App2,139.56
2004-08-24,App2,140.16
2004-08-25,App2,132
2004-08-26,App2,132.24
2004-08-27,App2,136.21
2004-08-19,App3,157.52
2004-08-20,App3,159.09
2004-08-23,App3,174.45
2004-08-24,App3,175.2
2004-08-25,App3,165
2004-08-26,App3,165.3
2004-08-27,App3,170.26