python如何绘制曲线图_python pandas plot画折线图如何显示x轴的值?

在使用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)

数据是我写的另外一个函数所产生的,若是大佬帮忙验证可替换掉。

折线图如图:

bVbap9P?w=1632&h=1070

想请问我的index的值:[‘Mon’, ‘Tue’, ‘Wed’, ‘Thur’, ‘Fri’, ‘Sat’, ‘Sun’]怎么才能显示在x轴上呢?

使用大佬回答的ax.set_xticklabels只能从周二开始?

bVbarKY?w=1492&h=1082

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值