我有這個圖表,但它沒有像我想要的那樣顯示資料。
我需要它在 x 圖中顯示從 1 到 24 的所有標簽(小時),而不是顯示(0、5、10、15、25),我希望它不顯示 x 圖中的 0 和 25。
import tkinter
import matplotlib
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
import numpy as np
root = tkinter.Tk()
root.wm_title("Embedding in Tk")
xlst=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
ylst=[26, 25, 21, 43, 68, 107, 221, 569, 575, 599, 586, 432, 486, 525, 410, 328, 251, 166, 153, 105, 123, 93, 54, 69]
matplotlib.use("TkAgg")
figure = Figure(figsize=(8,6), dpi=80)
plot = figure.add_subplot(1, 1, 1)
plot.bar(xlst, ylst)
canvas = FigureCanvasTkAgg(figure, root)
canvas.get_tk_widget().grid(row=0, column=0)
tkinter.mainloop()
用紅色箭頭標記的 0 和 25 我希望它以 1 開始并以 24 結束,也以綠色箭頭表示我想顯示所有小時
任何人都可以幫忙嗎?

uj5u.com熱心網友回復:
你只缺少一行,所以你去:
plot.set_xticks(np.arange(1,25))

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/357813.html
標籤:蟒蛇-3.x matplotlib
下一篇:繪制兩個陣列的最小值
