在使用python pandas Series plot画折线图时,不知道该如何显示x轴的值。
代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from matplotlib.font_manager import *
import tkinter as tk
from tkinter import ttk
import generate_situation01 as gs1
import get_phone_detail as gpd
import pandas as pd
class Test():
def __init__(self):
self.root = tk.Tk()
self.root.geometry("800x600")
self.data = gs1.main(1000)
self.lf = ttk.Labelframe(self.root, text='数据规律性')
self.lf.grid(row=1, column=1, sticky='nsew', padx=3, pady=3)
self.fig = Figure(figsize=(6, 5), dpi=100)
self.ax = self.fig.add_subplot(111)
self.show_btn = tk.Button(self.root, text='展示数据1', command=self.weekday_cost_show)
self.show_btn2 = tk.Button(self.root, text='展示数据2', command=self.phone_place_show)
self.show_btn3 = tk.Button(self.root, text='展示数据3', command=self.email_show)
self.show_btn.grid(row=0, column=0, sticky='w')
self.show_btn2.grid(row=0, column=1, sticky='w')
self.show_btn3.grid(row=0, column=2, sticky='w')
self.root.mainloop()
def weekday_cost_show(self):
self.ax.clear()
self.weekdays = self.data[['weekday']]
s = self.weekdays['weekday'].value_counts(sort=False)
s = s.reindex(['Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'])
s.plot(kind='line', ax=self.ax)
canvas = FigureCanvasTkAgg(self.fig, master=self.lf)
canvas.draw()
canvas.get_tk_widget().grid(row=0, column=0)
数据是我写的另外一个函数所产生的,若是大佬帮忙验证可替换掉。
折线图如图:
想请问我的index的值:[‘Mon’, ‘Tue’, ‘Wed’, ‘Thur’, ‘Fri’, ‘Sat’, ‘Sun’]怎么才能显示在x轴上呢?
使用大佬回答的ax.set_xticklabels只能从周二开始?