Why do we need the line data = array([angle, V_pd]).T
? We need it because ordinarily savetxt
would save the data in what Python calls 'unpacked' format, a format in which each variable corresponds to a different row instead of to a different column. That is, the default behavior is to save the data This is often convenient but is not what we wanted in this particular case. We therefore did the following clever trick before saving the data to a file: we created a 2D matrix of our data with the numpy command array([angle, V_pd])
, then used the .T
command to transpose the matrix , thereby flipping the rows and columns.
Other file handling methods
For more advanced data handling of spreadsheet data files, large data sets, and/or the handling of binary data, you may wish to try the commands provided by the Python Data Analysis Library package
pandas or the Hierarchical Data Format (HDF5) Python interface package
h5py instead of those provided by
numpy.
Plotting data using error bars
The most commonly used plotting package in Python is
Matplotlib. Here's an example of how to use it to generate plots with error bars representing the uncertainty in each data point. We use
angle
from the file
650 nm calibration.csv
for the x-axis values, we use
V_pd
for the y-axis values, and we use
V_pd_delta
for the uncertainty in the y-axis values.