Skip to content

Commit

Permalink
Add axis labels to same graphs in confinement report, format section …
Browse files Browse the repository at this point in the history
…labels
  • Loading branch information
r-k-g authored and philipbaileynar committed Aug 27, 2024
1 parent dadbbb5 commit 3159764
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/commons/rscommons/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ def box_plot(values, chart_title, file_path):
plt.savefig(file_path)


def histogram(values, bins, file_path):
def histogram(values, bins, file_path, xlabel=None, ylabel=None):

plt.clf()
plt.hist(values, bins)

if xlabel is not None:
plt.xlabel(xlabel)
if ylabel is not None:
plt.ylabel(ylabel)

if not os.path.isdir(os.path.dirname(file_path)):
os.makedirs(os.path.dirname(file_path))

Expand Down
5 changes: 3 additions & 2 deletions packages/confinement/confinement/confinement_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def report_content(self):
# charts and tables
self.raw_confinement(section_out)
for field in ['confinement_ratio', 'constriction_ratio']:
self.confinement_ratio(field, field, section_out)
format_label = field.replace('_', ' ').title()
self.confinement_ratio(field, format_label, section_out)

outputs = list(realization.find('Outputs'))
[self.layerprint(lyr, section_out, self.project_root) for lyr in outputs if lyr.tag in ['DEM', 'Raster', 'Vector', 'Geopackage']]
Expand All @@ -79,7 +80,7 @@ def confinement_ratio(self, db_field, label, parent=None):

image_path = os.path.join(
self.images_dir, '{}.png'.format(db_field.lower()))
histogram(data, 10, image_path)
histogram(data, 10, image_path, 'Confinement Ratio', 'Length (km)')

img_wrap = ET.Element('div', attrib={'class': 'imgWrap'})
img = ET.Element('img', attrib={
Expand Down

0 comments on commit 3159764

Please sign in to comment.