1

I have this chart but its not showing the data as I would like.

I need it to show all labels (hour) in the x plot from 1 to 24 instead its showing (0, 5, 10, 15, 25) and I would like it not to show the 0 and 25 of the x plot.

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()

The 0 and 25 marked with the red arrow I want it to start with 1 and end with 24 also with the green arrow I would like to show all hours.

Can anyone help?

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mrpy
  • 49
  • 6
  • Does this answer your question? [Changing the "tick frequency" on x or y axis in matplotlib?](https://stackoverflow.com/questions/12608788/changing-the-tick-frequency-on-x-or-y-axis-in-matplotlib) – BigBen Nov 16 '21 at 16:18

1 Answers1

2

You are missing just one line, so here you go:

plot.set_xticks(np.arange(1,25))

enter image description here

sehan2
  • 1,700
  • 1
  • 10
  • 23