Python in Physics
OSU logo
The content of this page is undergoing revision and will be moved to another site soon.
Graphing

Table of Contents

Matplotlib

  • When a plot is displayed, it is usefult to display it in a nonblocking way, that is the part of the program which created the plot continues to operate. In this way, the plot window need not be closed to continue execution. This forum discussion is insightful. Demonstration programs based on this discussion: nonblocking_plot.py, multiple_plot_windows.py.
  • Using Matplotlib in a Python shell.
  • For wxPython programming, read about creating a Matplotlib figure in a wx panel.
  • Introduction to Matplotlib OO class library.
  • The program frame_mpl_test_2.py imports frames_for_mpl.py and continuously scrolls a sine wave on a canvas within a wx frame. The plot is redrawn by hooking the plot to a timer event. The tricky part is having the plot use a function defined in the main program, not in the module defining the frame. This is accomplished in Main(frame) by the statement "frame.MakeData = Calc", where Calc is the function returning the data to be plotted. Note that Calc is not followed by () because a reference to the function is being made here, not a call of the function. Data is recalculated on a regular basis in the frame.SetTimer(time_interval) function, which binds the frame timer to the frame.PlotData(event) function which in turn invokes frame.MakeData(self), which is just Calc(frame). The function Calc(frame) creates the data set frame.data.
  • The program radio_delay_2_ain_nidaqmx.py imports nidaqmx.py and reads the AD signal in 1 second delay loop of 10 arrays. The problem is that it does not update the value rather reprints the first value.