3

I have a plot in a tkinter.Toplevel window and I would like to have it use a custom spaced x-axis. Currently it is set as default so the numbers are evenly spaced (0,5,10,15... etc.). I would like to have a tick mark for each data point I have (example 2,6,15,30). I am sure it is just some key word under some header, but I cannot figure out which one it is. Below is an example of the code that it would be going into.

import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.backends.backend_tkagg import NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import Tkinter as tk

root = tk.Toplevel(width=2000)
f = Figure()
ax = f.add_subplot(111)
zeroy = [0,25]
zerox = [0, 35]
p3 = ax.plot(zerox, zeroy, 'k-')
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas.get_tk_widget().grid(row=0)

toolbar = NavigationToolbar2TkAgg(canvas, root)
toolbar.grid(row=1, sticky=tk.W) 
toolbar.update() 
button = tk.Button(root, text='Quit', command = root.destroy)
button.grid(row=2)
root.mainloop()

I have tried to use ax.xticks(...) and f.add_axes(xticks=[1,2,5,7] but these didn't work. I have also tried a variety of other weak attempts without success. Any help would be appreciated. Thanks.

1 Answer 1

4
ax.set_xticks(ticks=[0,2,4,5,30,50])

Discovered this after messing with my code some more.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.