Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Setting x axys with matplotlib

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 whant it to start with 1 and end with 24 also with the green arrow i would like to show all hour´s

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Can anyone help?
enter image description here

>Solution :

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

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

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading