when using python pandas Series plot to draw a line chart, I don"t know how to display the value of the x-axis.
Code:
import 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)
The data is generated by another function I wrote, and can be replaced if the boss helps to verify it.
Line chart is shown in figure
index:["Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun"]x
ax.set_xticklabels