source: Examples/scripts/python/plot_carbon_data.py @ 4996

Last change on this file since 4996 was 3028, checked in by odonnell, 6 years ago

example scripts

File size: 2.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Author: Jackson O'Donnell
4#   jacksonhodonnell@gmail.com
5
6# An example script collecting data from a number of .gpx files
7#   and plotting some aggregate
8
9from __future__ import division, print_function
10import glob
11import matplotlib.pyplot as plt
12import pandas as pd
13# Add GSASII to PYTHONPATH so this can iport
14import GSASIIscriptable as G2sc
15
16
17def name(p):
18    return int(p.filename[-9:-4])
19
20
21def get_info(p):
22    """Get the desired info from a project. Returns a dictionary"""
23    phase = p.phases()[0]
24    hist = p.histograms()[0]
25    # Output unit cell information
26    output = phase.get_cell()
27    # Gather histogram residuals, occupancy of a given atom,
28    # goodness of fit
29    output.update(hist.residuals)
30    output.update({'O5 occupancy': phase.atom('O5').occupancy})
31    output['Rf^2'] = hist.data['data'][0]['0:0:Rf^2']
32    output['chisq'] = p['Covariance']['data']['Rvals']['chisq']
33    output['GOF'] = p['Covariance']['data']['Rvals']['GOF']
34    return output
35
36if __name__ == '__main__':
37    files = glob.glob('carbon_output/*.gpx')
38    projs = [G2sc.G2Project(f) for f in files]
39    projs.sort(key=name)
40
41    index = [name(p) for p in projs]
42    df = pd.DataFrame([get_info(p) for p in projs], index=index)
43
44    # Plot volume and occupancy together
45    plt.rc('text', usetex=True)
46    plt.rc('font', weight='bold', size='20')
47    fig, (ax1, axbot1) = plt.subplots(2)
48    df['O5 occupancy'].plot(ax=ax1, color='r')
49    ax1.set_ylabel('Oxygen occupancy, [0,1]', color='r')
50    ax1.tick_params('y', colors='r')
51
52    ax2 = ax1.twinx()
53    df['volume'].plot(ax=ax2, color='b')
54    ax2.set_ylabel(r'Unit Cell Volume, A$^3$', color='b')
55    ax2.tick_params('y', colors='b')
56
57    # Plot residuals on same scale
58    df['wR'].plot(ax=axbot1, label='wR')
59    df['Rf^2'].plot(ax=axbot1, label='Rf^2')
60    axbot1.set_ylabel(r'Residual (\%)')
61    axbot1.set_xlabel('Data set number')
62
63    axbot2 = axbot1.twinx()
64    df['GOF'].plot(ax=axbot2, label='GOF', color='r')
65    axbot2.set_ylabel(r'GOF')
66
67    lns = axbot1.lines + axbot2.lines
68    labs = [l.get_label() for l in lns]
69    axbot1.legend(lns, labs, loc=0)
70
71    fig.suptitle(r'Refined $\alpha$-MnO$_2$ at U$_{iso}$ = 0.01')
72
73    plt.show()
Note: See TracBrowser for help on using the repository browser.