I mentioned in the original post that you can do nice plotting with ATK + matplotlib. A specific example of this is how the I-V script plots the results, and we can present that in a bit more detail, for those interested.
Remember from the actual I-V calculation that we have stored the values of bias and current in an array called "iv".
The simplest version of a plotting code would look like this:
import matplotlib
matplotlib.use('Agg')
import pylab as P
from numpy import array
X = array(iv)[:,0]
Y = array(iv)[:,1]
P.plot(X,Y)
P.xlabel('Bias (Volt)')
P.ylabel('Current (Ampere)')
P.title('I-V curve for Li-H2-Li')
P.savefig('lih2li_iv.png')
This looks very much like Matlab, and should be trivial to understand. The plot is attached as "lih2li_iv.png", and we can see that there are some things we would like to improve one (no plot points, scaling of the y-axis values).
Now, in the actual I-V script we go a step beyond this, since we wish to give the user control over things like the output file name, plot title, axis labels, etc, but also
- scaling (currents are in microamperes)
- plot symbols and colors
- axis min/max
- ... and perhaps something more
There are many ways to solve that, but one simple way is to use a
dictionary. The script contains an internal dict(ionary) the defines the default values, and we then allow the user to pass another dict to the plot function, and use it to overwrite the defaults with any user-defined parameters.
A simple example of this technique is
# Default values
parameters = { 'a' : 5, 'b' : 3 }
# User-defined parameters
my_parameters = { 'b' : 8 }
# Apply user parameters
parameters.update(my_parameters)
After that, the dict "parameters" will have a=5 (default) and b=8 (user-defined).
We use this in the plot function of the I-V script as follows. The default values are:
plot_params = {
# Blue circles with a line is default plot style
'plot_color' : 'b',
'plot_symbol' : 'o-',
'ylabel' : 'Current (micro-Ampere)',
'xlabel' : 'Bias (V)',
'grid' : False,
'title' : 'I-V curve',
'ymin' : None,
'ymax' : None,
# Scaling factor for the y-axis
'yscale' : 1.e6
}
To result of using these default can be seen in the original post (updated!).
The user can then make his own preferences, like
my_plot_params = {
# I want a green line with X plot symbols
'plot_color' : 'g',
'plot_symbol' : 'x-',
# No scaling, please
'yscale' : 1
'ylabel' : 'Current (Ampere)',
# I want a grid
'grid' : False,
'title' : 'I-V curve',
}
He then passes this to the plot script:
ivcurve.plotIVCurve(iv,'lih2li_iv_green.png',my_plot_params)
The result is also attached, as "lih2li_iv_green.png".
As mentioned above already, more details on matplotlib is available on their webpage.
Hopefully this demonstrates some of the powerful stuff you can do with plotting inside ATK!