I made a GUI with TKinter that reads a scope trace from a agilent scope. I want the x axis to update when I change time/div. To update the x and y data I use set_xdata
and set_ydata
. Is there a similar method for updating the x limits?

- 11,891
- 53
- 45
- 80

- 29
- 1
- 2
-
Do you want the range or the ticks to change? – Eric O. Lebigot Jan 25 '13 at 02:28
-
Did you get this sorted out? – tacaswell Oct 05 '13 at 00:55
2 Answers
You need to understand a bit of the object hierarchy. You are calling set_xdata
on a Line2D
object, which is an Artist
which is associated with an Axes
object (which handles things like log vs linear, the x/y limits, axis label, tick location and labels) which is associated with a Figure
object (which groups together a bunch of axes objects, deals with the window manager (for gui), ect) and a canvas
object (which actually deals with translating all of the other objects to a picture on the screen).
If you are using Tkinter, I assume that you have an axes
object, (that I will call ax
).
ax = fig.subplot(111) # or where ever you want to get you `Axes` object from.
my_line = ax.plot(data_x, data_y)
# whole bunch of code
#
# more other code
# update your line object
my_line.set_xdata(new_x_data)
my_line.set_ydata(new_y_data)
# update the limits of the axes object that you line is drawn on.
ax.set_xlim([top, bottom])
ax.set_ylim([left, right])
so to update the data in the line, you need to update my_line
, to update the axes limits, you need to update ax
.

- 84,579
- 22
- 210
- 199
-
my code is set up similar to this one I found on hear (answer 2). I want to update the x limits in a similar way I update the y data. http://stackoverflow.com/questions/9997869/interactive-plot-based-on-tkinter-and-matplotlib – Mark Mitry Jan 25 '13 at 19:01
-
1@MarkMitry thanks are nice, up votes and accepted answers are better ;) – tacaswell Jan 25 '13 at 21:12
The pyplot.xlim()
function changes the range of the x axis (of the current Axes).
The set_xticks()
method of Axes sets the ticks. The current Axes can be obtained for instance with gca()
.

- 91,433
- 48
- 218
- 260