Pundit:Current Code

From PrattWiki
Revision as of 15:36, 13 February 2020 by DukeEgr93 (talk | contribs) (Created page with "This page will keep track of current trends in EGR 103. It is meant to be a companion piece to any previous tests and solutions in case things were done in a different way in...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This page will keep track of current trends in EGR 103. It is meant to be a companion piece to any previous tests and solutions in case things were done in a different way in the past.

Loading Data from a Text File

Prior to the Spring 2020 semester, text files were generally either tab or space separated data files and np.loadtxt() could be used to load them. Starting with Spring of 2020 we focused on learning how to use pd.read_table() and pd.read_csv() for these things.

Current

Determine the file type (tab separated; other-separated) and if other-separated, the separator. Determine if the file has a header row or not. See Pandas

Past

Prior semesters mainly used

data = np.loadtxt("Filename")

to load a rectangular array of data from a file with no headers and with columns separated by spaces or tabs.

Starting a Figure

Starting a figure has evolved with the matplotlib.pyplot module.

Current

See Python:Starting Plots for more detail, but most commonly, to create a single figure with a single set of axes in it, we are using:

fig = plt.figure(num=1, clear=True)
ax = fig.add_subplot(1, 1, 1)

or, if the axes are definitely not containing surface plots,

fig, ax = plt.subplots(num=1, clear=True)

Past

Prior semesters used a variety of different techniques to get a clear plot started; usually, this required creating and clearing the figure then re-creating it:

plt.figure(num=1).clf()
fig, ax = plt.subplots(num=1)