Skip to content

Commit

Permalink
Good plot
Browse files Browse the repository at this point in the history
  • Loading branch information
annndruha committed Dec 29, 2023
1 parent cb02c8f commit 2e5c151
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion generate_dataset/dataset_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def generate_dataset():
for folder in folders:
top, cls = os.path.split(folder)
cir_path = os.path.join(folder, cls + '.cir')
png_path = os.path.join(folder, cls + '.png')
changer = ParametersChanger(cir_path, GENERATE_SETTINGS_PATH)
changer.generate_circuits()
path = os.path.join('dataset', measurements_settings, cls)
Expand All @@ -31,7 +32,7 @@ def generate_dataset():
simulator.save_ivc(circuit, analysis, fname)

pname = os.path.join(path, f'{i}.png')
simulator.save_plot(circuit, analysis, pname)
simulator.save_plot(circuit, analysis, pname, png_path)



Expand Down
5 changes: 4 additions & 1 deletion generate_dataset/parameters_changer.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ def _params_repr(self, params_combination) -> str:
if param["cir_key"] is not None:
s_params.append(f'{param["cir_key"]}={param["value"]}')
else:
s_params.append(f'{param["value"]}{param["cir_unit"]}') # :.2f
if param["value"] > 1:
s_params.append(f'{param["value"]:.0f}{param["cir_unit"]}')
else:
s_params.append(f'{param["value"]:.4f}{param["cir_unit"]}')
els.append(f'{k}({", ".join(s_params)})')
return f"[{self.circuit_class}] {' '.join(els)}"
26 changes: 18 additions & 8 deletions generate_dataset/simulate_ivc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import csv
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
from PySpice.Spice.Parser import Circuit


Expand Down Expand Up @@ -44,14 +45,23 @@ def save_ivc(circuit, analysis, path):
csv_writer.writerow(analysis.VCurrent)

@staticmethod
def save_plot(circuit, analysis, path):
plt.figure(1, (10, 10))
plt.grid()
plt.plot(analysis.input_dummy, analysis.VCurrent)
plt.xlabel('Напряжение [В]')
plt.ylabel('Сила тока [А]')
plt.figtext(0.5, 0.8, s=circuit.title)
plt.savefig(path, dpi=200)
def save_plot(circuit, analysis, path, png_path):
fig, ax = plt.subplots(1, figsize=(6, 6))

ax.grid()
ax.plot(analysis.input_dummy, analysis.VCurrent)
ax.set_xlabel('Напряжение [В]')
ax.set_xlabel('Сила тока [А]')

arr_img = plt.imread(png_path)
im = OffsetImage(arr_img, zoom=.65)
ab = AnnotationBbox(im, (1, 0), xycoords='axes fraction', box_alignment=(1.1, -0.1))
ax.add_artist(ab)
# plt.tight_layout(pad=1, w_pad=3, h_pad=1)
# plt.figtext(0.9, 0.5, s=circuit.title)
# plt.figtext(0.9, 0.5, s=circuit.title)
ax.set_title(circuit.title)
plt.savefig(path, dpi=150)
plt.clf()

# def add_noise(self):
Expand Down

0 comments on commit 2e5c151

Please sign in to comment.