diff --git a/outputs/charts/org/hiero-ledger/difficulty_by_repo_30_days.png b/outputs/charts/org/hiero-ledger/difficulty_by_repo_30_days.png index fbe765f..fce7b6e 100644 Binary files a/outputs/charts/org/hiero-ledger/difficulty_by_repo_30_days.png and b/outputs/charts/org/hiero-ledger/difficulty_by_repo_30_days.png differ diff --git a/outputs/charts/org/hiero-ledger/difficulty_distribution_with_unknown_30_days.png b/outputs/charts/org/hiero-ledger/difficulty_distribution_with_unknown_30_days.png index 93a7cf2..68e75b4 100644 Binary files a/outputs/charts/org/hiero-ledger/difficulty_distribution_with_unknown_30_days.png and b/outputs/charts/org/hiero-ledger/difficulty_distribution_with_unknown_30_days.png differ diff --git a/outputs/charts/org/hiero-ledger/difficulty_distribution_without_unknown_30_days.png b/outputs/charts/org/hiero-ledger/difficulty_distribution_without_unknown_30_days.png index 1397448..0d80f3d 100644 Binary files a/outputs/charts/org/hiero-ledger/difficulty_distribution_without_unknown_30_days.png and b/outputs/charts/org/hiero-ledger/difficulty_distribution_without_unknown_30_days.png differ diff --git a/outputs/charts/org/hiero-ledger/gfi_pipeline.png b/outputs/charts/org/hiero-ledger/gfi_pipeline.png index 1179fa0..b77b214 100644 Binary files a/outputs/charts/org/hiero-ledger/gfi_pipeline.png and b/outputs/charts/org/hiero-ledger/gfi_pipeline.png differ diff --git a/outputs/charts/org/hiero-ledger/gfi_yearly_state_line.png b/outputs/charts/org/hiero-ledger/gfi_yearly_state_line.png index a54968b..17f6e8b 100644 Binary files a/outputs/charts/org/hiero-ledger/gfi_yearly_state_line.png and b/outputs/charts/org/hiero-ledger/gfi_yearly_state_line.png differ diff --git a/outputs/charts/org/hiero-ledger/maintainer_pipeline_by_repo.png b/outputs/charts/org/hiero-ledger/maintainer_pipeline_by_repo.png index 5408e0a..72016de 100644 Binary files a/outputs/charts/org/hiero-ledger/maintainer_pipeline_by_repo.png and b/outputs/charts/org/hiero-ledger/maintainer_pipeline_by_repo.png differ diff --git a/outputs/charts/org/hiero-ledger/maintainer_pipeline_yearly.png b/outputs/charts/org/hiero-ledger/maintainer_pipeline_yearly.png index 36a88be..e99879c 100644 Binary files a/outputs/charts/org/hiero-ledger/maintainer_pipeline_yearly.png and b/outputs/charts/org/hiero-ledger/maintainer_pipeline_yearly.png differ diff --git a/outputs/charts/org/hiero-ledger/total_gfi_gfic_by_repo.png b/outputs/charts/org/hiero-ledger/total_gfi_gfic_by_repo.png index 8db017c..d9b630f 100644 Binary files a/outputs/charts/org/hiero-ledger/total_gfi_gfic_by_repo.png and b/outputs/charts/org/hiero-ledger/total_gfi_gfic_by_repo.png differ diff --git a/src/hiero_analytics/plotting/bars.py b/src/hiero_analytics/plotting/bars.py index bbc39e6..41e56a7 100644 --- a/src/hiero_analytics/plotting/bars.py +++ b/src/hiero_analytics/plotting/bars.py @@ -337,8 +337,6 @@ def plot_stacked_bar( _annotate_bar_totals(ax, patches, totals, horizontal=True) ax.margins(y=HORIZONTAL_Y_MARGIN, x=HORIZONTAL_X_MARGIN) ax.set_xlim(0, _compute_horizontal_axis_limit(max_total, padding)) - legend_anchor = (0.5, -0.04) - bottom_rect = 0.05 else: if annotate_totals and len(df) <= 12: _annotate_bar_totals(ax, patches, totals, horizontal=False) @@ -347,14 +345,26 @@ def plot_stacked_bar( if is_numeric_or_datetime(df[x_col]) and (df[x_col] % 1 == 0).all(): ax.set_xticks(df[x_col]) ax.set_xticklabels([str(int(v)) for v in df[x_col]]) - legend_anchor = (0.5, -0.14) - bottom_rect = 0.14 + ## Adaptive Legend placement + labels_count = len(labels) legend_loc = "lower center" + legend_anchor = (0.5, -0.14) + layout_rect = (0, 0.14, 1.0, 1.0) + legend_ncol = min(labels_count, 4) + + if labels_count > 6: + legend_loc = "upper left" + legend_anchor = (1.02, 1.0) + layout_rect = (0, 0, 0.85, 1.0) + legend_ncol = 1 + + # Backward-compatible override. if legend_inside_bottom_right: legend_loc = "lower right" legend_anchor = (0.985, 0.02) - bottom_rect = 0.0 + layout_rect = (0, 0, 1.0, 1.0) + legend_ncol = min(labels_count, 4) finalize_chart( fig=fig, @@ -370,7 +380,7 @@ def plot_stacked_bar( legend_labels=labels, legend_loc=legend_loc, legend_bbox_to_anchor=legend_anchor, - legend_ncol=min(len(labels), 4), + legend_ncol=legend_ncol, legend_kwargs={"borderaxespad": 0.0}, - layout_rect=(0, bottom_rect, 1, 1.0), + layout_rect=layout_rect, ) diff --git a/src/hiero_analytics/plotting/lines.py b/src/hiero_analytics/plotting/lines.py index a02be17..b1bd408 100644 --- a/src/hiero_analytics/plotting/lines.py +++ b/src/hiero_analytics/plotting/lines.py @@ -180,6 +180,20 @@ def plot_multiline( ax.set_xlim(float(pivot.index.min()) - 0.15, float(pivot.index.max()) + 0.45) ax.margins(x=0.03, y=0.16) + legend_count = len(pivot.columns) + + ## Prefer Bottom legend, Right legend only when many items + if legend_count > 6: + legend_loc = "upper left" + legend_bbox_to_anchor = (1.02, 1.0) + legend_ncol = 1 + layout_rect = (0, 0, 0.85, 1.0) + else: + legend_loc = "lower center" + legend_bbox_to_anchor = (0.5, -0.18) + legend_ncol = min(legend_count, 4) + layout_rect = (0, 0.12, 1.0, 1.0) + finalize_chart( fig=fig, ax=ax, @@ -190,10 +204,9 @@ def plot_multiline( legend=True, rotate_x=rotate_x, grid_axis="y", - # Keep the legend in the header whitespace instead of on top of data. - legend_loc="upper right", - legend_bbox_to_anchor=(1, 1.14), - legend_ncol=min(len(pivot.columns), 3), + legend_loc=legend_loc, + legend_bbox_to_anchor=legend_bbox_to_anchor, + legend_ncol=legend_ncol, legend_kwargs={"borderaxespad": 0.0}, - layout_rect=(0, 0, 1, 0.92), - ) + layout_rect=layout_rect, + ) \ No newline at end of file