Difference between revisions of "Matplotlib DPL94 R1rho R2eff"

From relax wiki
Jump to navigation Jump to search
Line 8: Line 8:
 
import os
 
import os
 
from math import cos, sin
 
from math import cos, sin
 +
from numpy import array, float64
  
 
### plotting facility.
 
### plotting facility.
Line 19: Line 20:
 
from pipe_control.mol_res_spin import return_spin, spin_loop
 
from pipe_control.mol_res_spin import return_spin, spin_loop
 
# Import method to calculate the R1_rho offset data
 
# Import method to calculate the R1_rho offset data
from specific_analyses.relax_disp.disp_data import calc_rotating_frame_params, generate_r20_key, loop_exp_frq
+
from specific_analyses.relax_disp.disp_data import calc_rotating_frame_params, generate_r20_key, loop_exp_frq, loop_exp_frq_offset, loop_point, return_param_key_from_data, return_spin_lock_nu1
 +
from specific_analyses.relax_disp import optimisation
  
 
###############
 
###############
Line 27: Line 29:
 
res_state = os.path.join(res_folder, "DPL94", "results")
 
res_state = os.path.join(res_folder, "DPL94", "results")
 
spin_inte = ":52@N"
 
spin_inte = ":52@N"
 +
 +
# Interpolate graph settings
 +
num_points=1000
 +
num_points=100
 +
extend=500.0
 +
extend=500.0
 +
 +
################
 
spin_inte_rep = spin_inte.replace('#', '_').replace(':', '_').replace('@', '_')
 
spin_inte_rep = spin_inte.replace('#', '_').replace(':', '_').replace('@', '_')
  
Line 40: Line 50:
  
 
# Calculate the offset data
 
# Calculate the offset data
theta_spin_dic, Domega_spin_dic, w_eff_spin_dic, dic_key_list = calc_rotating_frame_params(spin=cdp.myspin, spin_id=spin_inte, verbosity=1)
+
theta_spin_dic, Domega_spin_dic, w_eff_spin_dic, dic_key_list = calc_rotating_frame_params(spin=cdp.myspin, spin_id=spin_inte, verbosity=0)
 
# Save the data in cdp to access it after execution of script.
 
# Save the data in cdp to access it after execution of script.
 
cdp.myspin.theta_spin_dic = theta_spin_dic
 
cdp.myspin.theta_spin_dic = theta_spin_dic
Line 46: Line 56:
 
cdp.myspin.dic_key_list = dic_key_list
 
cdp.myspin.dic_key_list = dic_key_list
  
# Create spin.r2 keys
+
############################
r2keys = []
+
# First creacte back calculated R2eff data for interpolated plots.
for exp_type, frq in loop_exp_frq():
+
############################
     r2keys.append(generate_r20_key(exp_type=exp_type, frq=frq) )
+
 
# Save the keys
+
 
cdp.r2keys = r2keys
+
# Return the original structure for frq, offset
 +
spin_lock_nu1 = return_spin_lock_nu1(ref_flag=False)
 +
# Prepare list to hold new data
 +
spin_lock_nu1_new = []
 +
 
 +
# Loop over the structures to generate data
 +
for ei in range(len(spin_lock_nu1)):
 +
     # Add a new dimension.
 +
    spin_lock_nu1_new.append([])
 +
 
 +
    # Then loop over the spectrometer frequencies.
 +
    for mi in range(len(spin_lock_nu1[ei])):
 +
        # Add a new dimension.
 +
        spin_lock_nu1_new[ei].append([])
  
x_w_eff = []
+
        # Finally the offsets.
x_theta = []
+
        for oi in range(len(spin_lock_nu1[ei][mi])):
x_disp_point = []
+
            # Add a new dimension.
y = []
+
            spin_lock_nu1_new[ei][mi].append([])
y_R1_rho = []
 
  
cdp.mydic = collections.OrderedDict()
+
            # No data.
 +
            if not len(spin_lock_nu1[ei][mi][oi]):
 +
                continue
  
for dic_key in cdp.myspin.dic_key_list:
+
            # Interpolate (adding the extended amount to the end).
    R1_rho_prime = cdp.myspin.r2[cdp.r2keys[0]]
+
            for di in range(num_points):
    R1 = cdp.myspin.ri_data['R1']
+
                point = (di + 1) * (max(spin_lock_nu1[ei][mi][oi])+extend) / num_points
    R1_rho = cdp.myspin.r2eff[dic_key]
+
                spin_lock_nu1_new[ei][mi][oi].append(point)
  
    # Store the R1_rho value
+
            # Convert to a numpy array.
    y_R1_rho.append(R1_rho)
+
            spin_lock_nu1_new[ei][mi][oi] = array(spin_lock_nu1_new[ei][mi][oi], float64)
  
    exp_type, frq_1e6, offset, point = dic_key.split("_")
+
# Then back calculate R2eff data for the interpolated points.
 +
cdp.myspin.back_calc = optimisation.back_calc_r2eff(spin=cdp.myspin, spin_id=spin_inte, spin_lock_nu1=spin_lock_nu1_new)
  
    # Get disp_point, the Spin-lock field strength
+
###### Store the data before plotting
    x_disp_point.append(float(point))
+
# Create a dictionary to hold data
 +
cdp.mydic = collections.OrderedDict()
  
    # Get w_eff
+
# Loop over the data structures
    w_eff = cdp.myspin.w_eff_spin_dic[dic_key]
+
for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True):
     x_w_eff.append(w_eff)
+
     r20_key = generate_r20_key(exp_type=exp_type, frq=frq)
  
     # Get theta
+
     # This is not used, but could be used to get Rex.
     theta = cdp.myspin.theta_spin_dic[dic_key]
+
     R1_rho_prime = cdp.myspin.r2[r20_key]
    x_theta.append(theta)
 
   
 
    # Get Domega
 
    Domega = Domega_spin_dic[dic_key]
 
  
     # Calculate y value
+
     # Get R1
     R1_rho_R2eff = (R1_rho - R1*cos(theta)*cos(theta)) / (sin(theta) * sin(theta))
+
     R1 = cdp.myspin.ri_data['R1']
     y.append(R1_rho_R2eff)
+
     R1_err = cdp.myspin.ri_data_err['R1']
  
 
     # Add to dic
 
     # Add to dic
 
     if exp_type not in cdp.mydic:
 
     if exp_type not in cdp.mydic:
 
         cdp.mydic[exp_type] = collections.OrderedDict()
 
         cdp.mydic[exp_type] = collections.OrderedDict()
     if frq_1e6 not in cdp.mydic[exp_type]:
+
     if frq not in cdp.mydic[exp_type]:
         cdp.mydic[exp_type][frq_1e6] = collections.OrderedDict()
+
         cdp.mydic[exp_type][frq] = collections.OrderedDict()
     if offset not in cdp.mydic[exp_type][frq_1e6]:
+
     if offset not in cdp.mydic[exp_type][frq]:
         cdp.mydic[exp_type][frq_1e6][offset] = collections.OrderedDict()
+
         cdp.mydic[exp_type][frq][offset] = collections.OrderedDict()
         cdp.mydic[exp_type][frq_1e6][offset]['point'] = []
+
        # X val
         cdp.mydic[exp_type][frq_1e6][offset]['theta'] = []
+
         cdp.mydic[exp_type][frq][offset]['point'] = []
         cdp.mydic[exp_type][frq_1e6][offset]['w_eff'] = []
+
         cdp.mydic[exp_type][frq][offset]['point_inter'] = []
         cdp.mydic[exp_type][frq_1e6][offset]['R1_rho'] = []
+
        cdp.mydic[exp_type][frq][offset]['theta'] = []
         cdp.mydic[exp_type][frq_1e6][offset]['R1_rho_R2eff'] = []
+
         cdp.mydic[exp_type][frq][offset]['w_eff'] = []
     cdp.mydic[exp_type][frq_1e6][offset]['point'].append(float(point))
+
        # Y val
    cdp.mydic[exp_type][frq_1e6][offset]['theta'].append(float(theta))
+
         cdp.mydic[exp_type][frq][offset]['R1_rho'] = []
    cdp.mydic[exp_type][frq_1e6][offset]['w_eff'].append(float(w_eff))
+
         cdp.mydic[exp_type][frq][offset]['R1_rho_err'] = []
    cdp.mydic[exp_type][frq_1e6][offset]['R1_rho'].append(float(R1_rho))
+
        cdp.mydic[exp_type][frq][offset]['R1_rho_bc'] = []
    cdp.mydic[exp_type][frq_1e6][offset]['R1_rho_R2eff'].append(float(R1_rho_R2eff))
+
        cdp.mydic[exp_type][frq][offset]['R1_rho_inter'] = []
 +
        # Y2 val
 +
        cdp.mydic[exp_type][frq][offset]['R1_rho_R2eff'] = []
 +
        cdp.mydic[exp_type][frq][offset]['R1_rho_R2eff_err'] = []
 +
 
 +
 
 +
    # Loop over the orginal dispersion points.
 +
     for point, di in loop_point(exp_type=exp_type, frq=frq, offset=offset, return_indices=True):
 +
        param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
 +
 
 +
        # X val
 +
        cdp.mydic[exp_type][frq][offset]['point'].append(point)
 +
        theta = theta_spin_dic[param_key]
 +
        cdp.mydic[exp_type][frq][offset]['theta'].append(theta)
 +
        cdp.mydic[exp_type][frq][offset]['w_eff'].append(w_eff_spin_dic[param_key])
 +
 
 +
        # Y val
 +
        R1_rho = cdp.myspin.r2eff[param_key]
 +
        cdp.mydic[exp_type][frq][offset]['R1_rho'].append(R1_rho)
 +
        R1_rho_err = cdp.myspin.r2eff_err[param_key]
 +
        cdp.mydic[exp_type][frq][offset]['R1_rho_err'].append(R1_rho_err)
 +
        cdp.mydic[exp_type][frq][offset]['R1_rho_bc'].append(cdp.myspin.r2eff_bc[param_key])
 +
 
 +
        # Y2 val
 +
        # Calc R1_rho_R2eff
 +
        R1_rho_R2eff = (R1_rho - R1*cos(theta)*cos(theta)) / (sin(theta) * sin(theta))
 +
        cdp.mydic[exp_type][frq][offset]['R1_rho_R2eff'].append(R1_rho_R2eff)
 +
        R1_rho_R2eff_err = (R1_rho_err - R1_err*cos(theta)*cos(theta)) / (sin(theta) * sin(theta))
 +
        cdp.mydic[exp_type][frq][offset]['R1_rho_R2eff_err'].append(R1_rho_R2eff_err)
 +
 
 +
    ## Loop over the new dispersion points.
 +
    for di in range(len(cdp.myspin.back_calc[ei][0][mi][oi])):
 +
        point = spin_lock_nu1_new[ei][mi][oi][di]
 +
 
 +
        # X val
 +
        cdp.mydic[exp_type][frq][offset]['point_inter'].append(point)  
 +
 
 +
        # Y val
 +
        R1_rho = cdp.myspin.back_calc[ei][0][mi][oi][di]
 +
        cdp.mydic[exp_type][frq][offset]['R1_rho_inter'].append(R1_rho)
 +
 
  
# Print values in dic
 
for exptype, frq_dic in cdp.mydic.items():
 
    for frq, offset_dic in frq_dic.items():
 
        for offset, val_dics in offset_dic.items():
 
            print exptype, frq, offset, val_dics['R1_rho'], val_dics['theta']
 
  
# Modify data
+
####### PLOT ####
 +
## Modify data
 
w_eff_div = 10**4
 
w_eff_div = 10**4
rem_points = 2
 
x_w_eff_mod = [x/w_eff_div for x in x_w_eff[:-rem_points]]
 
y_mod = y[:-rem_points]
 
  
# Define labels for plotting
+
## Define labels for plotting
 
plotlabel_R1_rho_R2eff = 'R1_rho_R2eff'
 
plotlabel_R1_rho_R2eff = 'R1_rho_R2eff'
 
plotlabel_R1_rho = 'R1_rho'
 
plotlabel_R1_rho = 'R1_rho'
 +
 +
ylabel_R1_rho = 'R1_rho [rad.s^-1]'
 +
ylabel_R1_rho_R2eff = 'R1_rho_R2eff [rad.s^-1]'
 +
 +
xlabel_theta = 'Rotating frame tilt angle [rad]'
 
xlabel_w_eff = 'Effective field in rotating frame [%s rad.s^-1]'%(str(w_eff_div))
 
xlabel_w_eff = 'Effective field in rotating frame [%s rad.s^-1]'%(str(w_eff_div))
xlabel_theta = 'Rotating frame tilt angle [rad]'
 
 
xlabel_lock = 'Spin-lock field strength [Hz]'
 
xlabel_lock = 'Spin-lock field strength [Hz]'
ylabel_R1_rho_R2eff = 'R1_rho_R2eff [rad.s^-1]'
 
ylabel_R1_rho = 'R1_rho [rad.s^-1]'
 
  
# Plot R1_rho_R2eff as function of w_eff
+
# Plot values in dic
plt.figure()
+
for exptype, frq_dic in cdp.mydic.items():
plt.plot(x_w_eff_mod, y_mod, 'o', label=plotlabel_R1_rho_R2eff)
+
    for frq, offset_dic in frq_dic.items():
plt.xlabel(xlabel_w_eff)
+
        for offset, val_dics in offset_dic.items():
plt.ylabel(ylabel_R1_rho_R2eff)
+
            # General plot label
plt.legend(loc='best')
+
            graphlabel = "%3.1f_%3.3f"%(frq/1E6, offset)
plt.grid(True)
+
            graphlabel_bc = "%3.1f_%3.3f_bc"%(frq/1E6, offset)
plt.ylim([0,16])
+
            graphlabel_inter = "%3.1f_%3.3f_inter"%(frq/1E6, offset)
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho_R2eff, xlabel_w_eff))
+
 
plt.savefig("matplotlib_%s_%s_w_eff.png"%(spin_inte_rep, plotlabel_R1_rho_R2eff) )
+
            # Plot 1: R1_rho as function of theta.
 +
            plt.figure(1)
 +
            plt.errorbar(val_dics['theta'], val_dics['R1_rho'], yerr=val_dics['R1_rho_err'], fmt='o', label=graphlabel)
 +
            #plt.plot(val_dics['theta'], val_dics['R1_rho'], '-o', label=graphlabel)
 +
 
 +
            # Plot 2: R1_rho_R2eff as function of w_eff
 +
            plt.figure(2)
 +
            x_w_eff_mod = [x/w_eff_div for x in val_dics['w_eff']]
 +
            plt.errorbar(x_w_eff_mod, val_dics['R1_rho_R2eff'], yerr=val_dics['R1_rho_R2eff_err'], fmt='o', label=graphlabel)
 +
            #plt.plot(x_w_eff_mod, val_dics['R1_rho_R2eff'], 'o', label=graphlabel)
 +
 
 +
            # Plot 3: R1_rho as function of as function of disp_point, the Spin-lock field strength
 +
            plt.figure(3)
 +
            line, = plt.plot(val_dics['point_inter'], val_dics['R1_rho_inter'], '-', label=graphlabel_inter)
 +
            plt.errorbar(val_dics['point'], val_dics['R1_rho'], yerr=val_dics['R1_rho_err'], fmt='o', label=graphlabel, color=line.get_color())
 +
            plt.plot(val_dics['point'], val_dics['R1_rho_bc'], 'D', label=graphlabel_bc, color=line.get_color())
 +
           
  
# Plot R1_rho_R2eff as function of theta
+
# Define settings for each graph
plt.figure()
+
# Plot 1: R1_rho as function of theta.
plt.plot(x_theta, y, 'o', label=plotlabel_R1_rho_R2eff)
+
plt.figure(1)
 
plt.xlabel(xlabel_theta)
 
plt.xlabel(xlabel_theta)
plt.ylabel(ylabel_R1_rho_R2eff)
+
plt.ylabel(ylabel_R1_rho)
 
plt.legend(loc='best')
 
plt.legend(loc='best')
 
plt.grid(True)
 
plt.grid(True)
 
plt.ylim([0,16])
 
plt.ylim([0,16])
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho_R2eff, xlabel_theta))
+
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho, xlabel_theta))
plt.savefig("matplotlib_%s_%s_theta.png"%(spin_inte_rep, plotlabel_R1_rho_R2eff) )
+
#plt.savefig("matplotlib_%s_%s_theta_sep.png"%(spin_inte_rep, plotlabel_R1_rho) )
  
# Plot R1_rho_R2eff as function of disp_point, the Spin-lock field strength
+
## Plot 2: R1_rho_R2eff as function of w_eff
plt.figure()
+
plt.figure(2)
plt.plot(x_disp_point, y, 'o', label=plotlabel_R1_rho_R2eff)
+
plt.xlabel(xlabel_w_eff)
plt.xlabel(xlabel_lock)
 
 
plt.ylabel(ylabel_R1_rho_R2eff)
 
plt.ylabel(ylabel_R1_rho_R2eff)
 
plt.legend(loc='best')
 
plt.legend(loc='best')
 
plt.grid(True)
 
plt.grid(True)
 
plt.ylim([0,16])
 
plt.ylim([0,16])
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho_R2eff, xlabel_lock))
+
plt.xlim([0,2])
plt.savefig("matplotlib_%s_%s_disp.png"%(spin_inte_rep, plotlabel_R1_rho_R2eff) )
+
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho_R2eff, xlabel_w_eff))
 +
#plt.savefig("matplotlib_%s_%s_w_eff.png"%(spin_inte_rep, plotlabel_R1_rho_R2eff) )
  
# Plot R1_rho as function of theta.
+
## Plot 3: R1_rho as function of as function of disp_point, the Spin-lock field strength
plt.figure()
+
plt.figure(3)
plt.plot(x_theta, y_R1_rho, 'o', label=plotlabel_R1_rho)
+
plt.xlabel(xlabel_lock)
plt.xlabel(xlabel_theta)
 
 
plt.ylabel(ylabel_R1_rho)
 
plt.ylabel(ylabel_R1_rho)
 
plt.legend(loc='best')
 
plt.legend(loc='best')
 
plt.grid(True)
 
plt.grid(True)
 
plt.ylim([0,16])
 
plt.ylim([0,16])
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho, xlabel_theta))
+
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho, xlabel_lock))
plt.savefig("matplotlib_%s_%s_theta.png"%(spin_inte_rep, plotlabel_R1_rho) )
+
#plt.savefig("matplotlib_%s_%s_w_eff.png"%(spin_inte_rep, plotlabel_R1_rho_R2eff) )
 
 
# Plot R1_rho as function of theta.
 
plt.figure()
 
for exptype, frq_dic in cdp.mydic.items():
 
    for frq, offset_dic in frq_dic.items():
 
        for offset, val_dics in offset_dic.items():
 
            graphlabel = "%s_%s"%(frq, offset)
 
            plt.plot(val_dics['theta'], val_dics['R1_rho'], '-o', label=graphlabel)
 
plt.ylabel(ylabel_R1_rho)
 
plt.xlabel(xlabel_theta)
 
plt.legend(loc='best')
 
plt.grid(True)
 
plt.ylim([0,16])
 
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho, xlabel_theta))
 
plt.savefig("matplotlib_%s_%s_theta_sep.png"%(spin_inte_rep, plotlabel_R1_rho) )
 
  
 
plt.show()
 
plt.show()

Revision as of 20:59, 14 March 2014

About

Code

File: r1rhor2eff.py

### python imports
import sys
import os
from math import cos, sin
from numpy import array, float64

### plotting facility.
import matplotlib.pyplot as plt

# Ordered dictionary
import collections

### relax modules
# Import some tools to loop over the spins.
from pipe_control.mol_res_spin import return_spin, spin_loop
# Import method to calculate the R1_rho offset data
from specific_analyses.relax_disp.disp_data import calc_rotating_frame_params, generate_r20_key, loop_exp_frq, loop_exp_frq_offset, loop_point, return_param_key_from_data, return_spin_lock_nu1
from specific_analyses.relax_disp import optimisation

###############

# You have to provide a DPL94 results state file
res_folder = "resultsR1"
res_state = os.path.join(res_folder, "DPL94", "results")
spin_inte = ":52@N"

# Interpolate graph settings
num_points=1000
num_points=100
extend=500.0
extend=500.0

################
spin_inte_rep = spin_inte.replace('#', '_').replace(':', '_').replace('@', '_')

# Load the state
state.load(res_state, force=True)

# Show pipes
pipe.display()
pipe.current()

# Get the spin of interest and save it in cdp, to access it after execution of script.
cdp.myspin = return_spin(spin_inte)

# Calculate the offset data
theta_spin_dic, Domega_spin_dic, w_eff_spin_dic, dic_key_list = calc_rotating_frame_params(spin=cdp.myspin, spin_id=spin_inte, verbosity=0)
# Save the data in cdp to access it after execution of script.
cdp.myspin.theta_spin_dic = theta_spin_dic
cdp.myspin.w_eff_spin_dic = w_eff_spin_dic
cdp.myspin.dic_key_list = dic_key_list

############################
# First creacte back calculated R2eff data for interpolated plots.
############################


# Return the original structure for frq, offset
spin_lock_nu1 = return_spin_lock_nu1(ref_flag=False)
# Prepare list to hold new data
spin_lock_nu1_new = []

# Loop over the structures to generate data
for ei in range(len(spin_lock_nu1)):
    # Add a new dimension.
    spin_lock_nu1_new.append([])

    # Then loop over the spectrometer frequencies.
    for mi in range(len(spin_lock_nu1[ei])):
        # Add a new dimension.
        spin_lock_nu1_new[ei].append([])

        # Finally the offsets.
        for oi in range(len(spin_lock_nu1[ei][mi])):
            # Add a new dimension.
            spin_lock_nu1_new[ei][mi].append([])

            # No data.
            if not len(spin_lock_nu1[ei][mi][oi]):
                continue

            # Interpolate (adding the extended amount to the end).
            for di in range(num_points):
                point = (di + 1) * (max(spin_lock_nu1[ei][mi][oi])+extend) / num_points
                spin_lock_nu1_new[ei][mi][oi].append(point)

            # Convert to a numpy array.
            spin_lock_nu1_new[ei][mi][oi] = array(spin_lock_nu1_new[ei][mi][oi], float64)

# Then back calculate R2eff data for the interpolated points.
cdp.myspin.back_calc = optimisation.back_calc_r2eff(spin=cdp.myspin, spin_id=spin_inte, spin_lock_nu1=spin_lock_nu1_new)

###### Store the data before plotting
# Create a dictionary to hold data
cdp.mydic = collections.OrderedDict()

# Loop over the data structures
for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True):
    r20_key = generate_r20_key(exp_type=exp_type, frq=frq)

    # This is not used, but could be used to get Rex.
    R1_rho_prime = cdp.myspin.r2[r20_key]

    # Get R1
    R1 = cdp.myspin.ri_data['R1']
    R1_err = cdp.myspin.ri_data_err['R1']

    # Add to dic
    if exp_type not in cdp.mydic:
        cdp.mydic[exp_type] = collections.OrderedDict()
    if frq not in cdp.mydic[exp_type]:
        cdp.mydic[exp_type][frq] = collections.OrderedDict()
    if offset not in cdp.mydic[exp_type][frq]:
        cdp.mydic[exp_type][frq][offset] = collections.OrderedDict()
        # X val
        cdp.mydic[exp_type][frq][offset]['point'] = []
        cdp.mydic[exp_type][frq][offset]['point_inter'] = []
        cdp.mydic[exp_type][frq][offset]['theta'] = []
        cdp.mydic[exp_type][frq][offset]['w_eff'] = []
        # Y val
        cdp.mydic[exp_type][frq][offset]['R1_rho'] = []
        cdp.mydic[exp_type][frq][offset]['R1_rho_err'] = []
        cdp.mydic[exp_type][frq][offset]['R1_rho_bc'] = []
        cdp.mydic[exp_type][frq][offset]['R1_rho_inter'] = []
        # Y2 val
        cdp.mydic[exp_type][frq][offset]['R1_rho_R2eff'] = []
        cdp.mydic[exp_type][frq][offset]['R1_rho_R2eff_err'] = []


    # Loop over the orginal dispersion points.
    for point, di in loop_point(exp_type=exp_type, frq=frq, offset=offset, return_indices=True):
        param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)

        # X val
        cdp.mydic[exp_type][frq][offset]['point'].append(point)
        theta = theta_spin_dic[param_key]
        cdp.mydic[exp_type][frq][offset]['theta'].append(theta)
        cdp.mydic[exp_type][frq][offset]['w_eff'].append(w_eff_spin_dic[param_key])

        # Y val
        R1_rho = cdp.myspin.r2eff[param_key]
        cdp.mydic[exp_type][frq][offset]['R1_rho'].append(R1_rho)
        R1_rho_err = cdp.myspin.r2eff_err[param_key]
        cdp.mydic[exp_type][frq][offset]['R1_rho_err'].append(R1_rho_err)
        cdp.mydic[exp_type][frq][offset]['R1_rho_bc'].append(cdp.myspin.r2eff_bc[param_key])

        # Y2 val
        # Calc R1_rho_R2eff
        R1_rho_R2eff = (R1_rho - R1*cos(theta)*cos(theta)) / (sin(theta) * sin(theta))
        cdp.mydic[exp_type][frq][offset]['R1_rho_R2eff'].append(R1_rho_R2eff)
        R1_rho_R2eff_err = (R1_rho_err - R1_err*cos(theta)*cos(theta)) / (sin(theta) * sin(theta))
        cdp.mydic[exp_type][frq][offset]['R1_rho_R2eff_err'].append(R1_rho_R2eff_err)

    ## Loop over the new dispersion points.
    for di in range(len(cdp.myspin.back_calc[ei][0][mi][oi])):
        point = spin_lock_nu1_new[ei][mi][oi][di]

        # X val
        cdp.mydic[exp_type][frq][offset]['point_inter'].append(point) 

        # Y val
        R1_rho = cdp.myspin.back_calc[ei][0][mi][oi][di]
        cdp.mydic[exp_type][frq][offset]['R1_rho_inter'].append(R1_rho)



####### PLOT ####
## Modify data
w_eff_div = 10**4

## Define labels for plotting
plotlabel_R1_rho_R2eff = 'R1_rho_R2eff'
plotlabel_R1_rho = 'R1_rho'

ylabel_R1_rho = 'R1_rho [rad.s^-1]'
ylabel_R1_rho_R2eff = 'R1_rho_R2eff [rad.s^-1]'

xlabel_theta = 'Rotating frame tilt angle [rad]'
xlabel_w_eff = 'Effective field in rotating frame [%s rad.s^-1]'%(str(w_eff_div))
xlabel_lock = 'Spin-lock field strength [Hz]'

# Plot values in dic
for exptype, frq_dic in cdp.mydic.items():
    for frq, offset_dic in frq_dic.items():
        for offset, val_dics in offset_dic.items():
            # General plot label
            graphlabel = "%3.1f_%3.3f"%(frq/1E6, offset)
            graphlabel_bc = "%3.1f_%3.3f_bc"%(frq/1E6, offset)
            graphlabel_inter = "%3.1f_%3.3f_inter"%(frq/1E6, offset)

            # Plot 1: R1_rho as function of theta.
            plt.figure(1)
            plt.errorbar(val_dics['theta'], val_dics['R1_rho'], yerr=val_dics['R1_rho_err'], fmt='o', label=graphlabel)
            #plt.plot(val_dics['theta'], val_dics['R1_rho'], '-o', label=graphlabel)

            # Plot 2: R1_rho_R2eff as function of w_eff
            plt.figure(2)
            x_w_eff_mod = [x/w_eff_div for x in val_dics['w_eff']]
            plt.errorbar(x_w_eff_mod, val_dics['R1_rho_R2eff'], yerr=val_dics['R1_rho_R2eff_err'], fmt='o', label=graphlabel)
            #plt.plot(x_w_eff_mod, val_dics['R1_rho_R2eff'], 'o', label=graphlabel)

            # Plot 3: R1_rho as function of as function of disp_point, the Spin-lock field strength
            plt.figure(3)
            line, = plt.plot(val_dics['point_inter'], val_dics['R1_rho_inter'], '-', label=graphlabel_inter)
            plt.errorbar(val_dics['point'], val_dics['R1_rho'], yerr=val_dics['R1_rho_err'], fmt='o', label=graphlabel, color=line.get_color())
            plt.plot(val_dics['point'], val_dics['R1_rho_bc'], 'D', label=graphlabel_bc, color=line.get_color())
            

# Define settings for each graph
# Plot 1: R1_rho as function of theta.
plt.figure(1)
plt.xlabel(xlabel_theta)
plt.ylabel(ylabel_R1_rho)
plt.legend(loc='best')
plt.grid(True)
plt.ylim([0,16])
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho, xlabel_theta))
#plt.savefig("matplotlib_%s_%s_theta_sep.png"%(spin_inte_rep, plotlabel_R1_rho) )

## Plot 2: R1_rho_R2eff as function of w_eff
plt.figure(2)
plt.xlabel(xlabel_w_eff)
plt.ylabel(ylabel_R1_rho_R2eff)
plt.legend(loc='best')
plt.grid(True)
plt.ylim([0,16])
plt.xlim([0,2])
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho_R2eff, xlabel_w_eff))
#plt.savefig("matplotlib_%s_%s_w_eff.png"%(spin_inte_rep, plotlabel_R1_rho_R2eff) )

## Plot 3: R1_rho as function of as function of disp_point, the Spin-lock field strength
plt.figure(3)
plt.xlabel(xlabel_lock)
plt.ylabel(ylabel_R1_rho)
plt.legend(loc='best')
plt.grid(True)
plt.ylim([0,16])
plt.title("%s \n %s as function of %s"%(spin_inte, ylabel_R1_rho, xlabel_lock))
#plt.savefig("matplotlib_%s_%s_w_eff.png"%(spin_inte_rep, plotlabel_R1_rho_R2eff) )

plt.show()

To run

relax -p r1rhor2eff.py

See also