Skip to content

Commit

Permalink
Shorten number format in histPlot
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmullaney committed Jan 10, 2025
1 parent f306160 commit be6121d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions python/lsst/analysis/tools/actions/plot/histPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def makePlot(
if nth_panel == 0 and nrows * ncols - len(self.panels) > 0:
nth_col -= 1
# Set font size for legend based on number of panels being plotted.
legend_font_size = max(4, int(8 - len(self.panels[panel].hists) / 2 - nrows // 2)) # type: ignore
legend_font_size = max(4, int(7 - len(self.panels[panel].hists) / 2 - nrows // 2)) # type: ignore
nums, meds, mads, stats_dict = self._makePanel(
data,
panel,
Expand Down Expand Up @@ -608,12 +608,16 @@ def _addStatisticsPanel(
legend_labels = (
([""] * (len(handles) + 1))
+ [stats_dict["statLabels"][0]]
+ [f"{x:.3g}" for x in stats_dict["stat1"]]
+ [f"{x:.3g}" if x > 0.01 else f"{x:.2e}" for x in stats_dict["stat1"]]
+ [stats_dict["statLabels"][1]]
+ [f"{x:.3g}" for x in stats_dict["stat2"]]
+ [f"{x:.3g}" if x > 0.01 else f"{x:.2e}" for x in stats_dict["stat2"]]
+ [stats_dict["statLabels"][2]]
+ [f"{x:.3g}" for x in stats_dict["stat3"]]
+ [f"{x:.3g}" if x > 0.01 else f"{x:.2e}" for x in stats_dict["stat3"]]
)
# Replace "e+0" with "e" and "e-0" with "e-" to save space.
legend_labels = [label.replace("e+0", "e") for label in legend_labels]
legend_labels = [label.replace("e-0", "e-") for label in legend_labels]

# Set the y anchor for the legend such that it roughly lines up with
# the panels.
yAnchor = max(0, yAnchor0 - 0.01) + nth_col * (0.008 + len(nums) * 0.005) * legend_font_size
Expand Down

0 comments on commit be6121d

Please sign in to comment.