From ccbea065c5688fdd0cd76f04f9783e66b51f4aad Mon Sep 17 00:00:00 2001 From: Xaseiresh Date: Fri, 3 May 2024 16:35:12 +0200 Subject: [PATCH] feat: :art: adjustments to plots as requested by Moritz --- Images/Datavis/generate_plot.py | 41 ++++++++++++++++++++++----------- Images/Datavis/plots.yml | 27 ++++++++++++++-------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/Images/Datavis/generate_plot.py b/Images/Datavis/generate_plot.py index 8bbb4a4..bf65b5a 100644 --- a/Images/Datavis/generate_plot.py +++ b/Images/Datavis/generate_plot.py @@ -40,7 +40,7 @@ def setup_step(plot_data, key): plot_data[key] = 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}..."); series = []; @@ -57,8 +57,13 @@ def read_ltspice_file(filename): line = line.rstrip("\n"); lre = Re(); - if lre.search("^Step Information: (.*) \(Step: .*\)$", line): - current_step = lre.last_match[1]; + if lre.search("^Step Information: ([^=]*)=([\d\.\+-]+)(\w?) \(Step: .*\)$", line): + 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: setup_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): 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('engineering' == plot_config['xformatter']): 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)) 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); 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)]; 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): plot_config['xformatter'] = 'engineering'; - legend_data = []; - for x in [0, int(num_steps/2), num_steps-1]: - step_name = plot_data['steps'][x]['step']; - for orig, replacement in plot_config.get('legend_replace', dict()).items(): - step_name = step_name.replace(orig, replacement); - - legend_data.append(step_name); + if(not 'xmin' in plot_config): + plot_config['xmin'] = np.min(plot_data['steps'][0][x_key]); + if(not 'xmax' in plot_config): + plot_config['xmax'] = np.max(plot_data['steps'][0][x_key]); - ax.legend(custom_lines, legend_data); + ax.legend(); decorate_ax(ax, plot_config); @@ -156,7 +171,7 @@ def generate_plot(plot_config): raise RuntimeError("Missing load type (`loadtype`) for plot config"); 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(); diff --git a/Images/Datavis/plots.yml b/Images/Datavis/plots.yml index 0a5ccf1..951071f 100644 --- a/Images/Datavis/plots.yml +++ b/Images/Datavis/plots.yml @@ -9,6 +9,8 @@ defaults: plots: - load: Parasitics/SingleStage_Cfp_Sweep.txt loadtype: ltspice + step_parameter: $C_{fp}$ + step_unit: F ofile: Parasitics/SingleStage_Cfp_Sweep.png @@ -16,9 +18,10 @@ plots: y_key: V(n002) dB 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 loadtype: ltspice + step_unit: $\Omega$ ofile: Parasitics/SingleStage_Rf_Sweep.png @@ -26,9 +29,10 @@ plots: y_key: V(n002) dB 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 loadtype: ltspice + step_unit: $\Omega$ ofile: Parasitics/SingleStage_Rf_Sweep_Noise.png @@ -42,6 +46,7 @@ plots: yplaces: 0 - load: Parasitics/SingleStage_LTC6268-10_Rf_Sweep_Noise.txt loadtype: ltspice + step_unit: $\Omega$ ofile: Parasitics/SingleStage_LTC_Rf_Sweep_Noise.png @@ -50,11 +55,12 @@ plots: x_key: frequency 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 yplaces: 0 - load: Parasitics/SingleStage_LTC6268-10_Cin_Sweep_Noise.txt loadtype: ltspice + step_unit: F ofile: Parasitics/SingleStage_LTC_Cin_Sweep_Noise.png @@ -62,12 +68,13 @@ plots: y_key: V(onoise)/1G x_key: frequency - title: Eingangsbezogener Noise-Level bei varriertem $C_{in}$ (LTC6268-10) - ylabel: Noise $\left(A/\sqrt{Hz}\right)$ + title: Eingangsbezogener Noise-Level bei varriertem $C_{\mathrm{in,p}}$ (LTC6268-10) + ylabel: Rauschen $\left(A/\sqrt{Hz}\right)$ yformatter: engineering yplaces: 0 - load: Parasitics/SingleStage_LTC6268-10_Cin_Sweep_Noise.txt loadtype: ltspice + step_unit: F ofile: Parasitics/SingleStage_LTC_Cin_Sweep_Noise_log.png @@ -75,13 +82,14 @@ plots: y_key: V(onoise)/1G x_key: frequency - title: Eingangsbezogener Noise-Level bei varriertem $C_{in}$ (LTC6268-10) - ylabel: Noise $\left(A/\sqrt{Hz}\right)$ + title: Eingangsbezogener Noise-Level bei varriertem $C_{\mathrm{in,p}}$ (LTC6268-10) + ylabel: Rauschen $\left(A/\sqrt{Hz}\right)$ yformatter: engineering yscale: log yplaces: 0 - load: Parasitics/SingleStage_GBWP_Sweep.txt loadtype: ltspice + step_unit: Hz ofile: Parasitics/SingleStage_GBWP_Sweep.png @@ -89,9 +97,10 @@ plots: y_key: V(n002) dB title: Verstärkung bei variiertem GBWP - ylabel: Gain (dB) + ylabel: Normalisierte Verstärkung (dB) - load: Parasitics/SingleStage_Cin_Sweep.txt loadtype: ltspice + step_unit: F ofile: Parasitics/SingleStage_Cin_Sweep.png @@ -99,4 +108,4 @@ plots: y_key: V(vout) dB title: Verstärkung bei variierter Eingangskapazität - ylabel: Gain (dB) \ No newline at end of file + ylabel: Normalisierte Verstärkung (dB) \ No newline at end of file