feat: 🎨 adjustments to plots as requested by Moritz

This commit is contained in:
Xaseiresh 2024-05-03 16:35:12 +02:00
parent 14b40eb1e0
commit ccbea065c5
2 changed files with 46 additions and 22 deletions

View file

@ -40,7 +40,7 @@ def setup_step(plot_data, key):
plot_data[key] = next_step; plot_data[key] = next_step;
plot_data['steps'].append(next_step); plot_data['steps'].append(next_step);
def read_ltspice_file(filename): def read_ltspice_file(filename, plot_config):
print(f"Reading LTSpice .txt file {filename}..."); print(f"Reading LTSpice .txt file {filename}...");
series = []; series = [];
@ -57,8 +57,13 @@ def read_ltspice_file(filename):
line = line.rstrip("\n"); line = line.rstrip("\n");
lre = Re(); lre = Re();
if lre.search("^Step Information: (.*) \(Step: .*\)$", line): if lre.search("^Step Information: ([^=]*)=([\d\.\+-]+)(\w?) \(Step: .*\)$", line):
current_step = lre.last_match[1]; step_param = plot_config.get('step_parameter', lre.last_match[1]);
value = f"{round(float(lre.last_match[2]), 2)}";
unit = f"{lre.last_match[3]}{plot_config.get('step_unit', '')}";
current_step = "{value:>6s} {unit:s}".format(value=value, unit=unit);
else: else:
setup_step(plot_data, current_step); setup_step(plot_data, current_step);
step = plot_data[current_step]; step = plot_data[current_step];
@ -93,6 +98,11 @@ def decorate_ax(ax, plot_config):
if('xscale' in plot_config): if('xscale' in plot_config):
ax.set_xscale(plot_config['xscale']); ax.set_xscale(plot_config['xscale']);
if('xmin' in plot_config):
ax.set_xlim(left=plot_config['xmin']);
if('xmax' in plot_config):
ax.set_xlim(right=plot_config['xmax']);
if('xformatter' in plot_config): if('xformatter' in plot_config):
if('engineering' == plot_config['xformatter']): if('engineering' == plot_config['xformatter']):
formatter = EngFormatter(places=plot_config.get('xplaces', 0), sep="\N{THIN SPACE}") formatter = EngFormatter(places=plot_config.get('xplaces', 0), sep="\N{THIN SPACE}")
@ -103,6 +113,14 @@ def decorate_ax(ax, plot_config):
formatter = EngFormatter(places=plot_config.get('yplaces', 0)) formatter = EngFormatter(places=plot_config.get('yplaces', 0))
ax.yaxis.set_major_formatter(formatter) ax.yaxis.set_major_formatter(formatter)
legend = ax.legend();
hp = legend._legend_box.get_children()[1]
for vp in hp.get_children():
for row in vp.get_children():
row.set_width(350) # need to adapt this manually
row.mode= "expand"
row.align="right"
ax.grid(True); ax.grid(True);
def plot_lt_sweep(fig, plot_config, plot_data): def plot_lt_sweep(fig, plot_config, plot_data):
@ -130,20 +148,17 @@ def plot_lt_sweep(fig, plot_config, plot_data):
matplotlib.lines.Line2D([0], [0], color=cmap(1.), lw=4)]; matplotlib.lines.Line2D([0], [0], color=cmap(1.), lw=4)];
for idx, step in enumerate(plot_data['steps']): for idx, step in enumerate(plot_data['steps']):
ax.plot(step[x_key], step[y_key], color=cmap(idx/(num_steps-1))); ax.plot(step[x_key], step[y_key], color=cmap(idx/(num_steps-1)), label=step['step']);
if(not 'xformatter' in plot_config): if(not 'xformatter' in plot_config):
plot_config['xformatter'] = 'engineering'; plot_config['xformatter'] = 'engineering';
legend_data = []; if(not 'xmin' in plot_config):
for x in [0, int(num_steps/2), num_steps-1]: plot_config['xmin'] = np.min(plot_data['steps'][0][x_key]);
step_name = plot_data['steps'][x]['step']; if(not 'xmax' in plot_config):
for orig, replacement in plot_config.get('legend_replace', dict()).items(): plot_config['xmax'] = np.max(plot_data['steps'][0][x_key]);
step_name = step_name.replace(orig, replacement);
legend_data.append(step_name); ax.legend();
ax.legend(custom_lines, legend_data);
decorate_ax(ax, plot_config); decorate_ax(ax, plot_config);
@ -156,7 +171,7 @@ def generate_plot(plot_config):
raise RuntimeError("Missing load type (`loadtype`) for plot config"); raise RuntimeError("Missing load type (`loadtype`) for plot config");
if(plot_config['loadtype'] == 'ltspice'): if(plot_config['loadtype'] == 'ltspice'):
plot_data = read_ltspice_file(os.path.join(YAML_DIR, plot_config['load'])); plot_data = read_ltspice_file(os.path.join(YAML_DIR, plot_config['load']), plot_config);
fig = plt.figure(); fig = plt.figure();

View file

@ -9,6 +9,8 @@ defaults:
plots: plots:
- load: Parasitics/SingleStage_Cfp_Sweep.txt - load: Parasitics/SingleStage_Cfp_Sweep.txt
loadtype: ltspice loadtype: ltspice
step_parameter: $C_{fp}$
step_unit: F
ofile: Parasitics/SingleStage_Cfp_Sweep.png ofile: Parasitics/SingleStage_Cfp_Sweep.png
@ -16,9 +18,10 @@ plots:
y_key: V(n002) dB y_key: V(n002) dB
title: Verstärkung bei konstantem $R_f = 1G\Omega$ und varriertem $C_{f}$ title: Verstärkung bei konstantem $R_f = 1G\Omega$ und varriertem $C_{f}$
ylabel: Gain (dB) ylabel: Normalisierte Verstärkung (dB)
- load: Parasitics/SingleStage_Rf_Sweep.txt - load: Parasitics/SingleStage_Rf_Sweep.txt
loadtype: ltspice loadtype: ltspice
step_unit: $\Omega$
ofile: Parasitics/SingleStage_Rf_Sweep.png ofile: Parasitics/SingleStage_Rf_Sweep.png
@ -26,9 +29,10 @@ plots:
y_key: V(n002) dB y_key: V(n002) dB
title: Verstärkung bei konstantem $C_{f} = 100fF$ und varriertem $R_{f}$ title: Verstärkung bei konstantem $C_{f} = 100fF$ und varriertem $R_{f}$
ylabel: Gain (dB) ylabel: Normalisierte Verstärkung (dB)
- load: Parasitics/SingleStage_Rf_Sweep_Noise.txt - load: Parasitics/SingleStage_Rf_Sweep_Noise.txt
loadtype: ltspice loadtype: ltspice
step_unit: $\Omega$
ofile: Parasitics/SingleStage_Rf_Sweep_Noise.png ofile: Parasitics/SingleStage_Rf_Sweep_Noise.png
@ -42,6 +46,7 @@ plots:
yplaces: 0 yplaces: 0
- load: Parasitics/SingleStage_LTC6268-10_Rf_Sweep_Noise.txt - load: Parasitics/SingleStage_LTC6268-10_Rf_Sweep_Noise.txt
loadtype: ltspice loadtype: ltspice
step_unit: $\Omega$
ofile: Parasitics/SingleStage_LTC_Rf_Sweep_Noise.png ofile: Parasitics/SingleStage_LTC_Rf_Sweep_Noise.png
@ -50,11 +55,12 @@ plots:
x_key: frequency x_key: frequency
title: Eingangsbezogener Noise-Level bei varriertem $R_{f}$ (LTC6268-10) title: Eingangsbezogener Noise-Level bei varriertem $R_{f}$ (LTC6268-10)
ylabel: Noise $\left(A/\sqrt{Hz}\right)$ ylabel: Rauschen $\left(A/\sqrt{Hz}\right)$
yformatter: engineering yformatter: engineering
yplaces: 0 yplaces: 0
- load: Parasitics/SingleStage_LTC6268-10_Cin_Sweep_Noise.txt - load: Parasitics/SingleStage_LTC6268-10_Cin_Sweep_Noise.txt
loadtype: ltspice loadtype: ltspice
step_unit: F
ofile: Parasitics/SingleStage_LTC_Cin_Sweep_Noise.png ofile: Parasitics/SingleStage_LTC_Cin_Sweep_Noise.png
@ -62,12 +68,13 @@ plots:
y_key: V(onoise)/1G y_key: V(onoise)/1G
x_key: frequency x_key: frequency
title: Eingangsbezogener Noise-Level bei varriertem $C_{in}$ (LTC6268-10) title: Eingangsbezogener Noise-Level bei varriertem $C_{\mathrm{in,p}}$ (LTC6268-10)
ylabel: Noise $\left(A/\sqrt{Hz}\right)$ ylabel: Rauschen $\left(A/\sqrt{Hz}\right)$
yformatter: engineering yformatter: engineering
yplaces: 0 yplaces: 0
- load: Parasitics/SingleStage_LTC6268-10_Cin_Sweep_Noise.txt - load: Parasitics/SingleStage_LTC6268-10_Cin_Sweep_Noise.txt
loadtype: ltspice loadtype: ltspice
step_unit: F
ofile: Parasitics/SingleStage_LTC_Cin_Sweep_Noise_log.png ofile: Parasitics/SingleStage_LTC_Cin_Sweep_Noise_log.png
@ -75,13 +82,14 @@ plots:
y_key: V(onoise)/1G y_key: V(onoise)/1G
x_key: frequency x_key: frequency
title: Eingangsbezogener Noise-Level bei varriertem $C_{in}$ (LTC6268-10) title: Eingangsbezogener Noise-Level bei varriertem $C_{\mathrm{in,p}}$ (LTC6268-10)
ylabel: Noise $\left(A/\sqrt{Hz}\right)$ ylabel: Rauschen $\left(A/\sqrt{Hz}\right)$
yformatter: engineering yformatter: engineering
yscale: log yscale: log
yplaces: 0 yplaces: 0
- load: Parasitics/SingleStage_GBWP_Sweep.txt - load: Parasitics/SingleStage_GBWP_Sweep.txt
loadtype: ltspice loadtype: ltspice
step_unit: Hz
ofile: Parasitics/SingleStage_GBWP_Sweep.png ofile: Parasitics/SingleStage_GBWP_Sweep.png
@ -89,9 +97,10 @@ plots:
y_key: V(n002) dB y_key: V(n002) dB
title: Verstärkung bei variiertem GBWP title: Verstärkung bei variiertem GBWP
ylabel: Gain (dB) ylabel: Normalisierte Verstärkung (dB)
- load: Parasitics/SingleStage_Cin_Sweep.txt - load: Parasitics/SingleStage_Cin_Sweep.txt
loadtype: ltspice loadtype: ltspice
step_unit: F
ofile: Parasitics/SingleStage_Cin_Sweep.png ofile: Parasitics/SingleStage_Cin_Sweep.png
@ -99,4 +108,4 @@ plots:
y_key: V(vout) dB y_key: V(vout) dB
title: Verstärkung bei variierter Eingangskapazität title: Verstärkung bei variierter Eingangskapazität
ylabel: Gain (dB) ylabel: Normalisierte Verstärkung (dB)