Skip to content

Bugfix/correct plotting - #54

Merged
EleniSmyrniou merged 17 commits into
masterfrom
bugfix/correct_plotting
Apr 1, 2026
Merged

Bugfix/correct plotting#54
EleniSmyrniou merged 17 commits into
masterfrom
bugfix/correct_plotting

Conversation

@EleniSmyrniou

Copy link
Copy Markdown
Collaborator

When we generate the plot cpts as "unlimited," i.e., not on A4, we notice that the scale bar at the top of the sounding jumps in some cases.

@EleniSmyrniou
EleniSmyrniou force-pushed the bugfix/correct_plotting branch from 77ea70c to 8af5f76 Compare February 2, 2026 10:36
Comment thread geolib_plus/plot_utils.py Outdated
if not (x_axis_type == "primary"):
vertical_rel_spacing += extra_label_spacing
vertical_rel_spacing += (
extra_label_spacing * CALIBRATED_LENGTH_FIGURE_SIZE / (ylim[0] - ylim[1])

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added as the spacing is also relative to the size of the whole figure

@EleniSmyrniou

EleniSmyrniou commented Feb 2, 2026

Copy link
Copy Markdown
Collaborator Author

The old approach used settings["secondary_top_axis_position"]], which:

  • Didn't adapt to different plot depths
  • Required manual tuning per configuration
  • Could cause overlaps with deeper plots

I changed the code so that it is automatic and not dependent on the input of the user.
This is done as follows by using the calculate_top_spine_position to calculate the vertical position for secondary x-axes to prevent overlap with axis labels and the information box at the top of CPT plots.

Spine sits above the multicolor labels and bellow the text box.
By using the same constants as the set_multicolor_label and scaled to the plot size the vertical position of the secondary axis is returned. This is done by scaling the same way as the labels with the CALIBRATED_LENGTH_FIGURE_SIZE / y_range

@EleniSmyrniou EleniSmyrniou self-assigned this Feb 2, 2026

@anoordam anoordam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the predrilled depth text box is at a wrong position i think

Comment thread geolib_plus/plot_utils.py Outdated
Comment on lines +139 to +144
vertical_rel_spacing = (
LABEL_VERTICAL_SPACING_RATIO * CALIBRATED_LENGTH_FIGURE_SIZE / (ylim[0] - ylim[1])
)
if not (x_axis_type == "primary"):
vertical_rel_spacing += extra_label_spacing
vertical_rel_spacing += (
extra_label_spacing * CALIBRATED_LENGTH_FIGURE_SIZE / (ylim[0] - ylim[1])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CALIBRATED_LENGTH_FIGURE_SIZE / (ylim[0] - ylim[1]) can be made a 1 variable

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment thread geolib_plus/plot_utils.py
Comment on lines +403 to +408
:param ylim: vertical limit [y_max, y_min]
:param extra_label_spacing: extra spacing for secondary axes
:return: position of top spine in axes coordinates
"""
y_min = ylim[1]
y_max = ylim[0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think its more standard to have [ymin, ymax] in the ylim, instead of [ymax,ymin]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or if it requires a whole refactr of the code I wouldnt change it, as it is not that important

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires a lot of changes, originally it is set in the function get_y_lims. Although normally it should be [ymin, ymax] in this case the [ymax,ymin] makes sense for plotting since the y axis is defined from ymax to ymin. I will not take any actions here

Comment thread geolib_plus/plot_utils.py Outdated
Comment on lines +411 to +415
# Calculate the vertical spacing used for multicolor labels
# From set_multicolor_label: vertical_rel_spacing = 0.06 * CALIBRATED_LENGTH_FIGURE_SIZE / y_range
# Plus extra spacing for secondary axes: extra_label_spacing * CALIBRATED_LENGTH_FIGURE_SIZE / y_range
# CALIBRATED_LENGTH_FIGURE_SIZE = 21 meters
# extra_label_spacing = 0.02

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this comment can go to the docstring at the top of this function

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment thread geolib_plus/plot_utils.py Outdated
)

return ax
return None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return None

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment thread tests/test_acceptance_plot.py Outdated
Comment on lines +84 to +86

# Vertical length of the graph in meter
# cpt.plot_settings.vertical_settings["length_graph"] = 50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Vertical length of the graph in meter
# cpt.plot_settings.vertical_settings["length_graph"] = 50

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment thread tests/test_plot_cpt.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these changes required?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! Otherwise the tests fail in the actions

Comment thread tests/test_plot_utils.py Outdated
Comment on lines +186 to +187
assert result == pytest.approx(expected)
assert result == pytest.approx(1.0336) # For 50m range

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you assert the same thing twice

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment thread tests/test_acceptance_plot.py Outdated
assert self.are_plots_identical(
generated_path, reference_path
), f"Generated plot for {cpt_file_xml.name} does not match reference."
#assert self.are_plots_identical(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you comment this check?

Comment thread tests/test_acceptance_plot.py Outdated
Comment on lines +29 to +31
if np.any(diff):
return True
return False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if np.any(diff):
return True
return False
return np.any(diff)

@sonarqubecloud

Copy link
Copy Markdown

@EleniSmyrniou
EleniSmyrniou merged commit c802f44 into master Apr 1, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants