susceptibility1/plot_chi2.py
2024-06-17 14:01:06 +02:00

72 lines
2.5 KiB
Python

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
from threefish.load import save_visualization
from threefish.plot.colorbar import colorbar_outside
from threefish.plot.limits import set_clim_same
from threefish.plot.tags import tag2
from threefish.RAM.calc_analytics import calc_nonlin_analytic_values
from threefish.RAM.plot_subplots import plt_RAM_perc
from threefish.RAM.reformat_matrix import convert_csv_str_to_float
from threefish.defaults import default_figsize, default_settings
from threefish.plot.plotstyle import plot_style
from threefish.RAM.values import perc_model_full
rc('text', usetex=True)
def plot_chi2():
frame, frame2 = calc_nonlin_analytic_values()
default_settings() # ts=13, ls=13, fs=13, lw = 0.7
plot_style()
default_figsize(column=2, length=2.5)
fig1, ax = plt.subplots(1, 2)
plt.subplots_adjust(bottom=0.2, wspace=0.35, left=0.1, right=0.92)
###################################################
# plot transfer function
frame = frame.astype(complex)
ax[0].plot(frame.index, np.abs(frame['transfer']), color='black')
ax[0].set_xlabel(r'$f_{1}$')
ax[0].set_ylabel(r'$|\chi_{1}|$')
ax[0].set_xlim(0, frame.index[-1])
ylim = ax[0].get_ylim()
ax[0].set_ylim(0, ylim[-1])
###################################################
# plot matrix
frame2.columns = frame2.index
new_keys, stack_plot = convert_csv_str_to_float(frame2)
im = plt_RAM_perc(ax[1], 'perc', np.abs(stack_plot))
set_clim_same([im],
mats=[np.abs(stack_plot)],
lim_type='up',
nr_clim='perc',
clims='',
percnr=perc_model_full())
pos_rel = -0.12
cbar, left, bottom, width, height = colorbar_outside(ax[1],
im,
add=5,
width=0.01)
ax[1].set_xlabel(r'$f_{1}$')
ax[1].set_ylabel(r'$f_{2}$')
ax[1].set_xticks_delta(0.2)
ax[1].set_xticks_delta(0.2)
ax[1].set_xlim(frame2.columns[0] - 0.01, frame2.columns[-1])
ax[1].set_ylim(frame2.columns[0] - 0.01, frame2.columns[-1])
cbar, left, bottom, width, height = colorbar_outside(ax[1], im, add=5, width=0.01)
cbar.set_label(r'$|\chi_{2}|$', rotation=90, labelpad=8)
tag2(axes=ax, xoffs=[-0.5, -5.5], yoffs=1.7) # ax_ams[3],
save_visualization()
if __name__ == '__main__':
plot_chi2()