import matplotlib.pyplot as plt

One of the most developed and widely used package in Python is matplotlib. There are several sub libraries for matplotlib, pyplotlib provides most of what you need for 2-d plotting. We are only scratching the surface is in this class. For a wider reference on matplotlib and pyplot check out these links:

  • pyplotlib
  • gallery .

    # define T array 
    T = np.array([0.35, 0.8, 1.25]) 
    # define L array 
    L = np.array([10, 20, 30]) 

    Here we are defining two 1-d arrays. Lets call them T and L.

    #plot L vs. T

    To plot we simply the function plot. Here we are plotting three data points. The T array (x1,x2,x3) and the L array (y1,y2,y3). The points can be drawn in multiple styles and colors. Here we are specifying that we would like them 'ro' meaning red circles. Refer to this link Symbol type and color on how you can change the styles and the colors of your data set.

    #y label
    plt.ylabel('Length (cm)') 
    #x label
    plt.xlabel(' T^{2}(Second^2)')

    These two lines help you label the y-axis and the x-axis.

    #save the plot in a png file

    You can save the plot you just created using savefig. If you would like to display this plot for a final check use the command display on your terminal followed by the file name. In this case display foo.png 

    show displays the plot on the computer screen. No screen output is produced before this function is called.