<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.eleceng.adelaide.edu.au/personal/dabbott/wiki/index.php?action=history&amp;feed=atom&amp;title=Code_Guide</id>
	<title>Code Guide - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.eleceng.adelaide.edu.au/personal/dabbott/wiki/index.php?action=history&amp;feed=atom&amp;title=Code_Guide"/>
	<link rel="alternate" type="text/html" href="https://www.eleceng.adelaide.edu.au/personal/dabbott/wiki/index.php?title=Code_Guide&amp;action=history"/>
	<updated>2026-06-25T03:27:08Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://www.eleceng.adelaide.edu.au/personal/dabbott/wiki/index.php?title=Code_Guide&amp;diff=20662&amp;oldid=prev</id>
		<title>A1666715: Created page with &quot;==Basic Description== The data captured from AEMO is stored in a database built on the HDF5 format. A more detailed description of the structure can be found in section 2.4. T...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.eleceng.adelaide.edu.au/personal/dabbott/wiki/index.php?title=Code_Guide&amp;diff=20662&amp;oldid=prev"/>
		<updated>2017-11-27T03:31:16Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Basic Description== The data captured from AEMO is stored in a database built on the HDF5 format. A more detailed description of the structure can be found in section 2.4. T...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Basic Description==&lt;br /&gt;
The data captured from AEMO is stored in a database built on the&lt;br /&gt;
HDF5 format. A more detailed description of the structure can be&lt;br /&gt;
found in section 2.4. The basic premise of our solution was to use&lt;br /&gt;
a web scraper to download the data files from AEMO, then extract&lt;br /&gt;
the pertinent data from these files and rearrange them into&lt;br /&gt;
a more easy to use and logical format. The AEMO data comes&lt;br /&gt;
in spreadsheet form, with data from one five minute sample per&lt;br /&gt;
spreadsheet or one days data per spreadsheet depending on the&lt;br /&gt;
dataset.&lt;br /&gt;
&lt;br /&gt;
===Tracking Time===&lt;br /&gt;
Keeping track of the sample times was very important for this&lt;br /&gt;
project. As the samples are recorded by AEMO in discrete five&lt;br /&gt;
minute (or thirty minute) intervals, we chose to simply use a reference&lt;br /&gt;
point and data indices to track the passage of time. This&lt;br /&gt;
allowed us to save significant memory space as storing time data&lt;br /&gt;
separately would have meant two values per data point rather&lt;br /&gt;
than just one. We chose a reference time of 1st January 2015&lt;br /&gt;
at 00:00:00 (the start of the new year). This means that midday&lt;br /&gt;
on January 1st 2015 has an index of 144. The functions Sample-&lt;br /&gt;
ToDatetime and DatetimeToSample perform the conversion between&lt;br /&gt;
sample index and time strings.&lt;br /&gt;
&lt;br /&gt;
==Database Modules==&lt;br /&gt;
ausp_archivedownloader: Downloads files from the AEMO&lt;br /&gt;
archive that have not been previously downloaded.&lt;br /&gt;
&lt;br /&gt;
ausp_configuration: This file is where all user defined settings&lt;br /&gt;
are stored. This includes websites, spreadsheet indices,&lt;br /&gt;
database structure and attributes.&lt;br /&gt;
&lt;br /&gt;
ausp_databasesetup: Creates a database structure based on&lt;br /&gt;
the user defined lists of structure data in the configuration.&lt;br /&gt;
&lt;br /&gt;
ausp_datetimetosample: Converts date-time strings to sample&lt;br /&gt;
numbers.&lt;br /&gt;
&lt;br /&gt;
ausp_dbupdater: Searches the AEMO archive files for files that&lt;br /&gt;
have not been downloaded. Then downloads and processes&lt;br /&gt;
the files into the database.&lt;br /&gt;
&lt;br /&gt;
ausp_filelogger: Logs downloaded file names into the file log&lt;br /&gt;
dataset.&lt;br /&gt;
&lt;br /&gt;
ausp_firstrun: This is the first module to run if there is no&lt;br /&gt;
database in place. It will setup a database, fill data and set&lt;br /&gt;
attributes.&lt;br /&gt;
&lt;br /&gt;
ausp_generaldownloader: Downloads a file that from a list&lt;br /&gt;
of filenames&lt;br /&gt;
&lt;br /&gt;
ausp_importdispatchisdata: Performs the processing to transfer&lt;br /&gt;
data from AEMO Dispatch spreadsheet into the database&lt;br /&gt;
&lt;br /&gt;
ausp_importpvactualdata: Performs the processing to transfer&lt;br /&gt;
data from AEMO PV spreadsheet into the database&lt;br /&gt;
&lt;br /&gt;
ausp_importscadadata: Performs the processing to transfer&lt;br /&gt;
data from AEMO SCADA spreadsheet into the database&lt;br /&gt;
&lt;br /&gt;
ausp_parse: Parses the AEMO website for the spreadsheet or&lt;br /&gt;
zipfile file names&lt;br /&gt;
&lt;br /&gt;
ausp_rawdatafileprocessor: Processes spreadsheets downloaded&lt;br /&gt;
from AEMO, extracting and placing the data into&lt;br /&gt;
the database.&lt;br /&gt;
&lt;br /&gt;
ausp_sampletodatetime: Converts a sample index to a datetime&lt;br /&gt;
string based on the reference time listed in the configuration&lt;br /&gt;
file&lt;br /&gt;
&lt;br /&gt;
ausp_scrapelistoffilesarchive: Creates lists of files that&lt;br /&gt;
are on AEMO data dashboard (Archive) for each of the&lt;br /&gt;
three datasets used: SCADA, Reports and rooftop PV.&lt;br /&gt;
&lt;br /&gt;
ausp_scrapelistoffilescurrent: Creates lists of files that&lt;br /&gt;
are on AEMO data dashboard (Current) for each of the&lt;br /&gt;
three datasets used: SCADA, Reports and rooftop PV.&lt;br /&gt;
&lt;br /&gt;
ausp_setgeneratorattributes: Sets generator attributes from&lt;br /&gt;
the NEM Registration list spreadsheet provided by AEMO&lt;br /&gt;
&lt;br /&gt;
ausp_setinterconnectorattributes: Sets interconnector attributes&lt;br /&gt;
based on the user defined attributes in the configuration&lt;br /&gt;
module&lt;br /&gt;
&lt;br /&gt;
ausp_setregionattribute: Sets region attributes based on the&lt;br /&gt;
user defined attributes in the configuration module&lt;br /&gt;
&lt;br /&gt;
==GA Module==&lt;br /&gt;
The GA module contains all the functions required to run the GA&lt;br /&gt;
as we have for this project. The functions are:&lt;br /&gt;
&lt;br /&gt;
generate_parent: Generates a list of specified length containing&lt;br /&gt;
randomly generated values between 0 and 1. This is&lt;br /&gt;
a real valued parent that can be used in a fitness function&lt;br /&gt;
to determine a fitness as required. It is a simple matter to&lt;br /&gt;
instead make discrete parents if that is what is required.&lt;br /&gt;
&lt;br /&gt;
generate_population: Generates a population of parents using&lt;br /&gt;
the generate_parent function. This population can be&lt;br /&gt;
any integer value.&lt;br /&gt;
&lt;br /&gt;
mutate: This function traverses a parent and mutates genes based&lt;br /&gt;
on a mutation probability. A mutation involves replacing&lt;br /&gt;
the gene with a randomly generated new gene. In this case,&lt;br /&gt;
the genes are real valued in the range [0, 1], but could be&lt;br /&gt;
modified to discrete as required.&lt;br /&gt;
&lt;br /&gt;
crossover: The crossover function takes a population as its main&lt;br /&gt;
input and outputs a new population of the same size that&lt;br /&gt;
has undergone the crossover procedure. Crossover requires&lt;br /&gt;
pairs of parents and each parent is only considered once&lt;br /&gt;
per generation and so the population size must be divisible&lt;br /&gt;
by two to ensure all parents are considered. An error will&lt;br /&gt;
be raised if the population is not divisible by two.&lt;br /&gt;
&lt;br /&gt;
tournament_selection: This function takes a population then&lt;br /&gt;
pairs the parents up at random and compares the fitness&lt;br /&gt;
of each pair. The parent with the better fitness is kept&lt;br /&gt;
while the other parent is discarded. This function outputs&lt;br /&gt;
a population that is half the size of the input population&lt;br /&gt;
and so should generally be run twice in each generation to&lt;br /&gt;
ensure population size is consistent throughout the simulation.&lt;br /&gt;
As the function pairs up parents, the population size&lt;br /&gt;
must again be divisible by two.&lt;br /&gt;
&lt;br /&gt;
fitness: This is the key user determined function for the GA.&lt;br /&gt;
This function will change depending on the aims, constraints&lt;br /&gt;
and requirements of each simulation. The function must&lt;br /&gt;
utilise a parent to determine its output or else the GA will&lt;br /&gt;
essentially be a fancy random number generator.&lt;br /&gt;
&lt;br /&gt;
main: This function puts all the other functions together to allow&lt;br /&gt;
simple operation of the GA. The steps of the main function&lt;br /&gt;
are described generally in figure 4.&lt;br /&gt;
&lt;br /&gt;
==Useful Code Fragments==&lt;br /&gt;
===Using matplotlib on a Mac===&lt;br /&gt;
I ran into an issue using python to plot using matplotlib on macOS.&lt;br /&gt;
Importing matplotlib in the following way solved the problem.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
2 import matplotlib as mpl&lt;br /&gt;
&lt;br /&gt;
3 mpl.use(’TkAgg’)&lt;br /&gt;
&lt;br /&gt;
4 import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
5 import any_other_packages_as_required&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Retrieving data from a .csv===&lt;br /&gt;
Without using any other packages, the data in a column of a .csv&lt;br /&gt;
file can be extracted to a python list using the following:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
1 data = []&lt;br /&gt;
&lt;br /&gt;
2 column_index = 0&lt;br /&gt;
&lt;br /&gt;
3 with open (’file.csv’,’r’) as file:&lt;br /&gt;
&lt;br /&gt;
4 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for lines in file:&lt;br /&gt;
&lt;br /&gt;
5 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;try:&lt;br /&gt;
&lt;br /&gt;
6 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;x = lines.split(’,’)&lt;br /&gt;
&lt;br /&gt;
7 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;data.append(float(x[column_index]))&lt;br /&gt;
&lt;br /&gt;
8 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;except:&lt;br /&gt;
&lt;br /&gt;
9 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;pass&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create a .csv file from a list of lists===&lt;br /&gt;
It was often useful to export data from the database to a .csv file&lt;br /&gt;
for later retrieval. There are a few ways to do this. The first&lt;br /&gt;
method uses the pandas package:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
1 import pandas as pd&lt;br /&gt;
&lt;br /&gt;
2&lt;br /&gt;
&lt;br /&gt;
3 column_data = [colA, colB, colC]&lt;br /&gt;
&lt;br /&gt;
4 labels = [’A’, ’B’, ’C’]&lt;br /&gt;
&lt;br /&gt;
5&lt;br /&gt;
&lt;br /&gt;
6 df = pd.DataFrame(column_data)&lt;br /&gt;
&lt;br /&gt;
7 df = df.transpose() # Remove this line if you want rows of data&lt;br /&gt;
&lt;br /&gt;
8 df.columns = labels&lt;br /&gt;
&lt;br /&gt;
9 pd.DataFrame.to_csv(df, ’filename.csv’, index = False)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To achieve the same result with default packages:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
1 labels = [’A’, ’B’]&lt;br /&gt;
&lt;br /&gt;
2 colAdata = [some_data]&lt;br /&gt;
&lt;br /&gt;
3 colBdata = [some_other_data]&lt;br /&gt;
&lt;br /&gt;
4 RowsAsStrings = [ ]&lt;br /&gt;
&lt;br /&gt;
5&lt;br /&gt;
&lt;br /&gt;
6 # Convert data to strings&lt;br /&gt;
&lt;br /&gt;
7 for i in range (0,len (longest_column)):&lt;br /&gt;
&lt;br /&gt;
8 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;RowsAsStrings.append(str(colAdata[i]) + ’,’ + str(colBdata[i]))&lt;br /&gt;
&lt;br /&gt;
9&lt;br /&gt;
&lt;br /&gt;
10 # Write strings to a file&lt;br /&gt;
&lt;br /&gt;
11 with open (’file.csv’, ’w+’) as file:&lt;br /&gt;
&lt;br /&gt;
12 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;file.writelines(’labels’)&lt;br /&gt;
&lt;br /&gt;
13 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for i in data_text:&lt;br /&gt;
&lt;br /&gt;
14 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;file.writelines(i + ’\n’)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Extract data from database===&lt;br /&gt;
Extracting data from the database is simple. For example this&lt;br /&gt;
code will retrieve all the demand data for the SA1 region:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
1 import h5py&lt;br /&gt;
&lt;br /&gt;
2&lt;br /&gt;
&lt;br /&gt;
3 with h5py.File(’STORPROJ_Database.h5’, ’r’) as f:&lt;br /&gt;
&lt;br /&gt;
4 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;demand_data = f[’Regions’][’SA1’][’Demand’][...,0]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Extracting data over a specified time frame:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
1 import h5py&lt;br /&gt;
&lt;br /&gt;
2 from AUSP_DatetimeToSample import DatetimeToSample as d2s&lt;br /&gt;
&lt;br /&gt;
3&lt;br /&gt;
&lt;br /&gt;
4 start_date = d2s (’2016/09/01 00:00:00’)&lt;br /&gt;
&lt;br /&gt;
5 end_date = d2s (’2017/09/01 00:00:00’)&lt;br /&gt;
&lt;br /&gt;
6&lt;br /&gt;
&lt;br /&gt;
7 with h5py.File(’STORPROJ_Database.h5’, ’r’) as f:&lt;br /&gt;
&lt;br /&gt;
8 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;demand_data = f[’Regions’][’SA1’][’Demand’][start_date:end_date][...,0]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Extracting and summing several known datasets.&lt;br /&gt;
The following code will extract all the data from the generators&lt;br /&gt;
HDWF1 and HDWF2 and sum across each sample resulting in an&lt;br /&gt;
array of summed generator outputs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
1 import h5py&lt;br /&gt;
&lt;br /&gt;
2 import numpy as np&lt;br /&gt;
&lt;br /&gt;
3&lt;br /&gt;
&lt;br /&gt;
4 with h5py.File(’STORPROJ_Database.h5’, ’r’) as f:&lt;br /&gt;
&lt;br /&gt;
5 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;data = np.nansum(zip(f[’DUIDs’][’HDWF1’][...,0],f[’DUIDs’][’HDWF2’][...,0]),1)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally, extracting all data from a range of datasets that have an&lt;br /&gt;
attribute that is the same. This example retrieves all generators&lt;br /&gt;
that are in the SA1 region with a primary fuel source of &amp;quot;wind&amp;quot;.&lt;br /&gt;
It also skips past any generators that have no attributes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
1 import h5py&lt;br /&gt;
&lt;br /&gt;
2 import numpy as np&lt;br /&gt;
&lt;br /&gt;
3&lt;br /&gt;
&lt;br /&gt;
4 with h5py.File(’STORPROJ_Database.h5’,’r’) as f:&lt;br /&gt;
&lt;br /&gt;
5 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for generator in f[’DUIDs’]:&lt;br /&gt;
&lt;br /&gt;
6 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if f[’DUIDs’][generator].attrs.keys( ) != [ ]:&lt;br /&gt;
&lt;br /&gt;
7 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if f[’DUIDs’][generator].attrs[’Fuel Source - Primary’ ] == &amp;quot;Wind&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
8 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if f[’DUIDs’][generator].attrs[’Region’] == &amp;quot;SA1&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
9 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;sa_wind = [np.nansum(x) for x in zip(sa_wind,f[’DUIDs’][generator][...,0])]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Plotting and Animating===&lt;br /&gt;
Plotting data is simple using matplotlib and the documentation&lt;br /&gt;
is full of information and examples on how to fully customise&lt;br /&gt;
your plots. The following examples shows how simple it is to get&lt;br /&gt;
a quick plot:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
1 import matplotlib as mpl&lt;br /&gt;
&lt;br /&gt;
2 mpl.use(’TkAgg’) # macOS only!&lt;br /&gt;
&lt;br /&gt;
3 import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
5 data = [some_data]&lt;br /&gt;
&lt;br /&gt;
6&lt;br /&gt;
&lt;br /&gt;
7 plt.plot(data)&lt;br /&gt;
&lt;br /&gt;
8 plt.show()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Animating is a bit trickier and I found the examples confusing&lt;br /&gt;
at first so here is an example of how to animate some data:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
1 import ma tplot l ib as mpl&lt;br /&gt;
&lt;br /&gt;
2 mpl.use(’TkAgg’)&lt;br /&gt;
&lt;br /&gt;
3 import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
4 import matplotlib.animation as animation&lt;br /&gt;
&lt;br /&gt;
5&lt;br /&gt;
&lt;br /&gt;
6 data = [some_data]&lt;br /&gt;
&lt;br /&gt;
7 fig = plt.figure()&lt;br /&gt;
&lt;br /&gt;
8 axis = fig.add_axes([0.1, 0.1, 0.8, 0.7])&lt;br /&gt;
&lt;br /&gt;
9&lt;br /&gt;
&lt;br /&gt;
10 def animate (frames, kwargs):&lt;br /&gt;
&lt;br /&gt;
11 &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;plt.plot(data[frames])&lt;br /&gt;
&lt;br /&gt;
12&lt;br /&gt;
&lt;br /&gt;
13 ani = animation.FuncAnimation(fig, animate, interval = 1000, frames = len(data), kwargs = None)&lt;br /&gt;
&lt;br /&gt;
14 ani.save(’filename.mp4’)&lt;br /&gt;
&lt;br /&gt;
15 plt.show()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, the FuncAnimation function creates the animation&lt;br /&gt;
using the user written function &amp;quot;animate&amp;quot; to create all the frames&lt;br /&gt;
of the animation. The frames parameter is a generator (similar&lt;br /&gt;
to a list of a range, e.g. frames = 10 is similar to, but not the&lt;br /&gt;
same as frames = range(0, 10)). The interval between frames in&lt;br /&gt;
this example is 1000ms, or 1s. The animate function can be as&lt;br /&gt;
complex as necessary and as long as the frames input changes&lt;br /&gt;
the plot, there will be an animation video at the end. I found&lt;br /&gt;
that the video file that is created works better if the frames are&lt;br /&gt;
short in duration (20ms or so). This means that an animation will&lt;br /&gt;
usually need a large number of frames.&lt;/div&gt;</summary>
		<author><name>A1666715</name></author>
	</entry>
</feed>