Skip to content

Commit

Permalink
feat: display image info on generated image
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan Le committed May 16, 2024
1 parent 486f411 commit 7a17986
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions chem_spectra/lib/composer/ni.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ def tf_img(self):
plt.ylabel("Y ({})".format(self.core.label['y']), fontsize=18)
plt.locator_params(nbins=self.__plt_nbins())
plt.grid(False)

self.__generate_info_box(plt)

# Save
tf_img = tempfile.NamedTemporaryFile(suffix='.png')
plt.savefig(tf_img, format='png')
Expand All @@ -499,6 +502,25 @@ def tf_img(self):
plt.cla()
return tf_img


def __generate_info_box(self, plotlib):
if not self.core.is_sec:
return
core_dic = self.core.dic
sec_data_key = ['MN', 'MW', 'MP', 'D']
result = []
for key in sec_data_key:
dic_value = core_dic.get(key, [])
key_str = f"{key}={dic_value[0]}" if len(dic_value) > 0 else None
if key_str is not None:
result.append(key_str)

info_str = '\n'.join(result)
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
ax = plotlib.gca()
ax.text(0.05, 0.95, info_str, fontsize=14, verticalalignment='top', bbox=props, transform=ax.transAxes)


def __prepare_metadata_info_for_csv(self, csv_writer: csv.DictWriter):
csv_writer.writerow({
'Anodic E(V)': 'Measurement type',
Expand Down

0 comments on commit 7a17986

Please sign in to comment.