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='數(shù)據(jù)規(guī)律性')
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='展示數(shù)據(jù)1', command=self.weekday_cost_show)
self.show_btn2 = tk.Button(self.root, text='展示數(shù)據(jù)2', command=self.phone_place_show)
self.show_btn3 = tk.Button(self.root, text='展示數(shù)據(jù)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)
數(shù)據(jù)是我寫的另外一個函數(shù)所產(chǎn)生的,若是大佬幫忙驗(yàn)證可替換掉。
折線圖如圖:
想請問我的index的值:[‘Mon’, ‘Tue’, ‘Wed’, ‘Thur’, ‘Fri’, ‘Sat’, ‘Sun’]怎么才能顯示在x軸上呢?
使用大佬回答的ax.set_xticklabels只能從周二開始?
總結(jié)
以上是生活随笔為你收集整理的python如何绘制曲线图_python pandas plot画折线图如何显示x轴的值?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 京东方:中短期看随着终端库存逐渐去化,面
- 下一篇: 苹果供应商赛尔康拟将印度员工人数增加逾一