# file: lecture_07/plot.py # # revision history: # # 20230911 (JP): initial version # # This program plots data from a file. # # To run this script, do this: # # python plot.py filename.txt # #------------------------------------------------------------------------------ # import required system modules # import os import sys import numpy as np import matplotlib.pyplot as plt #------------------------------------------------------------------------------ # # main program # #------------------------------------------------------------------------------ # load the data # data = np.loadtxt(sys.argv[1], dtype='f', delimiter=',') # convert to x-y vectors using a matrix transpose # #dataT = data.transpose() #x = dataT[0] #y = dataT[1] # alternately, slice the matrix # x = data[:,0] y = data[:,1] # plot the axes # plt.axis([-5, 5, -5, 5]) # plot the data # plt.plot(x, y) # add the title # plt.title("Our Data") # addi the labels # plt.ylabel("y-axis") plt.xlabel("x-axis") plt.show() # # end of file