fix(legend): position chart legends outside plot area to prevent overlap#89
Conversation
Signed-off-by: Adityarya11 <arya050411@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses legend overlap in Matplotlib charts by relocating legends to a dedicated right-side margin so plotted data and axis labels aren’t obscured (fixes #70).
Changes:
- Updated
plot_multiline(line charts) to place the legend outside the plot area on the right and reserve layout space vialayout_rect. - Updated
plot_stacked_bar(stacked bar charts) to place the legend outside the plot area on the right and reserve layout space vialayout_rect. - Added an updated generated chart image under
outputs/charts/....
Reviewed changes
Copilot reviewed 2 out of 8 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/hiero_analytics/plotting/lines.py |
Moves multiline legend to the right sidebar and reserves space using layout_rect. |
src/hiero_analytics/plotting/bars.py |
Moves stacked-bar legend to the right sidebar and reserves space using layout_rect (including handling for legend_inside_bottom_right). |
outputs/charts/org/hiero-ledger/gfi_pipeline.png |
Adds a regenerated chart artifact reflecting the new legend layout. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
danielmarv
left a comment
There was a problem hiding this comment.
LGTM
Because it gives visibility to the X axis scales and labling
exploreriii
left a comment
There was a problem hiding this comment.
I disagree this is a good solution, because this narrows all the charts windows significantly in some cases
We could instead just put the legend below the x axis? or at least choose the optimal location by type of chart
I have added backward compatibility, bottom legend, and the right legend only when there are too many items in the legend |
Signed-off-by: Adityarya11 <arya050411@gmail.com>
exploreriii
left a comment
There was a problem hiding this comment.
I think we will have to think in the future how to handle the different needs for charts, as this is hard-guessing the placement. But much improved, thank you!
|
@MonaaEid request re-review |
Changes
legend_bbox_to_anchor=(1.02, 1),legend_loc="upper left").layout_rectadjusted to reserve margin on the right (layout_rect=(0, 0, 0.85, 1)), guaranteeing that the legend has a fixed area and won’t obscure chart content.FIXES #70