日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2023/12/15 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)

數據是我寫的另外一個函數所產生的,若是大佬幫忙驗證可替換掉。

折線圖如圖:

想請問我的index的值:[‘Mon’, ‘Tue’, ‘Wed’, ‘Thur’, ‘Fri’, ‘Sat’, ‘Sun’]怎么才能顯示在x軸上呢?

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

總結

以上是生活随笔為你收集整理的python如何绘制曲线图_python pandas plot画折线图如何显示x轴的值?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。