Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 28, 2025

The StatsPlots extension had significant code repetition across plot functions for container management, attribute setup, and palette creation. This refactors common patterns into reusable helpers.

Helper Functions Added

  • clear_container! - Clears plot container using empty!()
  • setup_plot_attributes - Returns (gr_back, attributes, attributes_redux) based on backend
  • create_extended_palette - Creates extended palette with alpha reduction
  • group_container_by_model_and_merge_diffs - Groups by model name and merges diff dicts
  • create_reduced_vector_and_diffdict - Creates reduced vector and computes diff dict

Functions Updated

  • plot_model_estimates / plot_model_estimates!
  • plot_irf / plot_irf!
  • plot_solution / plot_solution!
  • plot_conditional_forecast / plot_conditional_forecast!
  • plot_conditional_variance_decomposition

Example

Before:

gr_back = StatsPlots.backend() == StatsPlots.Plots.GRBackend()
if !gr_back
    attrbts = merge(DEFAULT_PLOT_ATTRIBUTES, Dict(:framestyle => :box))
else
    attrbts = merge(DEFAULT_PLOT_ATTRIBUTES, Dict())
end
attributes = merge(attrbts, plot_attributes)
attributes_redux = copy(attributes)
delete!(attributes_redux, :framestyle)

After:

gr_back, attributes, attributes_redux = setup_plot_attributes(plot_attributes)

Net reduction of ~150 lines.

Original prompt

in the StatsPlot extension identify code that ahndles elements of the containers. write functions so that theinidiviual plot functions are not as long and repetitive


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 28, 2025 11:34
…ots extension

Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
…used push_if_no_duplicate! function

Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor plot functions for better code reuse Refactor StatsPlots extension: Extract helper functions for container handling Nov 28, 2025
Copilot AI requested a review from thorek1 November 28, 2025 11:39
Copilot finished work on behalf of thorek1 November 28, 2025 11:39
@github-actions
Copy link

Benchmark Results

main 601a9cd... main / 601a9cd...
FS2000/NSSS 13.3 ± 0.46 μs 15.2 ± 0.9 μs 0.878 ± 0.06
FS2000/covariance 0.116 ± 0.003 ms 0.12 ± 0.026 ms 0.968 ± 0.21
FS2000/irf 0.991 ± 0.046 ms 0.999 ± 0.026 ms 0.992 ± 0.053
FS2000/jacobian 0.764 ± 0.002 μs 0.762 ± 0.0031 μs 1 ± 0.0048
FS2000/lyapunov/bartels_stewart 0.102 ± 0.0021 ms 0.101 ± 0.0024 ms 1.01 ± 0.032
FS2000/lyapunov/bicgstab 0.0444 ± 0.0014 ms 0.0443 ± 0.0014 ms 1 ± 0.045
FS2000/lyapunov/doubling 0.0406 ± 0.015 ms 0.0515 ± 0.015 ms 0.789 ± 0.37
FS2000/lyapunov/gmres 26.4 ± 3.1 μs 26.6 ± 3.5 μs 0.993 ± 0.18
FS2000/qme/doubling 0.121 ± 0.0025 ms 0.123 ± 0.0029 ms 0.99 ± 0.031
FS2000/qme/schur 0.0683 ± 0.016 ms 0.0854 ± 0.013 ms 0.8 ± 0.23
NAWM_EAUS_2008/NSSS 2.73 ± 0.049 ms 7.07 ± 0.62 ms 0.386 ± 0.034
NAWM_EAUS_2008/covariance 25.3 ± 0.17 ms 29.3 ± 0.43 ms 0.863 ± 0.014
NAWM_EAUS_2008/irf 27 ± 0.41 ms 31.1 ± 1.1 ms 0.868 ± 0.033
NAWM_EAUS_2008/jacobian 0.0611 ± 0.0037 ms 0.062 ± 0.0041 ms 0.985 ± 0.088
NAWM_EAUS_2008/lyapunov/bartels_stewart 28.9 ± 0.65 ms 28.6 ± 1.5 ms 1.01 ± 0.059
NAWM_EAUS_2008/lyapunov/bicgstab 0.221 ± 0.0045 s 0.215 ± 0.0095 s 1.03 ± 0.05
NAWM_EAUS_2008/lyapunov/doubling 16.6 ± 0.58 ms 16.7 ± 0.78 ms 0.998 ± 0.058
NAWM_EAUS_2008/lyapunov/gmres 0.14 ± 0.0015 s 0.141 ± 0.0041 s 0.993 ± 0.031
NAWM_EAUS_2008/qme/doubling 23 ± 0.57 ms 23 ± 0.7 ms 0.999 ± 0.039
NAWM_EAUS_2008/qme/schur 16.5 ± 0.49 ms 15.7 ± 0.5 ms 1.05 ± 0.046
Smets_Wouters_2007/NSSS 0.16 ± 0.012 ms 0.16 ± 0.012 ms 1 ± 0.11
Smets_Wouters_2007/covariance 1.66 ± 0.04 ms 1.66 ± 0.04 ms 1 ± 0.034
Smets_Wouters_2007/irf 5.53 ± 0.21 ms 5.56 ± 0.25 ms 0.996 ± 0.058
Smets_Wouters_2007/jacobian 10.4 ± 22 μs 30.9 ± 2.1 μs 0.335 ± 0.72
Smets_Wouters_2007/lyapunov/bartels_stewart 1.52 ± 0.013 ms 1.51 ± 0.015 ms 1.01 ± 0.013
Smets_Wouters_2007/lyapunov/bicgstab 6.18 ± 0.05 ms 6.09 ± 0.16 ms 1.01 ± 0.029
Smets_Wouters_2007/lyapunov/doubling 0.965 ± 0.012 ms 0.965 ± 0.013 ms 1 ± 0.018
Smets_Wouters_2007/lyapunov/gmres 6.81 ± 0.45 ms 6.81 ± 0.47 ms 1 ± 0.096
Smets_Wouters_2007/qme/doubling 1.73 ± 0.015 ms 1.74 ± 0.021 ms 0.994 ± 0.015
Smets_Wouters_2007/qme/schur 1.41 ± 0.023 ms 1.43 ± 0.03 ms 0.985 ± 0.026
time_to_load 8.28 ± 0.018 s 8.26 ± 0.026 s 1 ± 0.0039
main 601a9cd... main / 601a9cd...
FS2000/NSSS 0.357 k allocs: 18.8 kB 0.357 k allocs: 18.8 kB 1
FS2000/covariance 1.06 k allocs: 0.13 MB 1.06 k allocs: 0.13 MB 1
FS2000/irf 6.98 k allocs: 0.335 MB 6.98 k allocs: 0.335 MB 1
FS2000/jacobian 1 allocs: 16 B 1 allocs: 16 B 1
FS2000/lyapunov/bartels_stewart 0.074 k allocs: 0.0656 MB 0.074 k allocs: 0.0656 MB 1
FS2000/lyapunov/bicgstab 0.087 k allocs: 0.0377 MB 0.087 k allocs: 0.0377 MB 1
FS2000/lyapunov/doubling 0.063 k allocs: 0.0393 MB 0.063 k allocs: 0.0393 MB 1
FS2000/lyapunov/gmres 0.145 k allocs: 0.0815 MB 0.145 k allocs: 0.0815 MB 1
FS2000/qme/doubling 0.2 k allocs: 0.0431 MB 0.2 k allocs: 0.0431 MB 1
FS2000/qme/schur 0.266 k allocs: 0.0842 MB 0.266 k allocs: 0.0842 MB 1
NAWM_EAUS_2008/NSSS 1.65 k allocs: 1.51 MB 2.66 k allocs: 5.07 MB 0.298
NAWM_EAUS_2008/covariance 4.23 k allocs: 15.5 MB 5.24 k allocs: 19 MB 0.813
NAWM_EAUS_2008/irf 0.101 M allocs: 16.3 MB 0.102 M allocs: 19.9 MB 0.821
NAWM_EAUS_2008/jacobian 7 allocs: 0.709 MB 7 allocs: 0.709 MB 1
NAWM_EAUS_2008/lyapunov/bartels_stewart 0.173 k allocs: 4.92 MB 0.181 k allocs: 4.92 MB 1
NAWM_EAUS_2008/lyapunov/bicgstab 0.09 k allocs: 5.66 MB 0.09 k allocs: 5.66 MB 1
NAWM_EAUS_2008/lyapunov/doubling 0.07 k allocs: 6.87 MB 0.07 k allocs: 6.87 MB 1
NAWM_EAUS_2008/lyapunov/gmres 0.393 k allocs: 0.0415 GB 0.393 k allocs: 0.0415 GB 1
NAWM_EAUS_2008/qme/doubling 0.309 k allocs: 6.29 MB 0.309 k allocs: 6.29 MB 1
NAWM_EAUS_2008/qme/schur 0.419 k allocs: 7.41 MB 0.419 k allocs: 7.41 MB 1
Smets_Wouters_2007/NSSS 1.26 k allocs: 0.0594 MB 1.26 k allocs: 0.0728 MB 0.816
Smets_Wouters_2007/covariance 3.07 k allocs: 1.34 MB 3.07 k allocs: 1.35 MB 0.99
Smets_Wouters_2007/irf 0.0332 M allocs: 2.2 MB 0.0332 M allocs: 2.21 MB 0.994
Smets_Wouters_2007/jacobian 7 allocs: 0.0612 MB 7 allocs: 0.0612 MB 1
Smets_Wouters_2007/lyapunov/bartels_stewart 0.084 k allocs: 0.441 MB 0.08 k allocs: 0.44 MB 1
Smets_Wouters_2007/lyapunov/bicgstab 0.089 k allocs: 0.469 MB 0.089 k allocs: 0.469 MB 1
Smets_Wouters_2007/lyapunov/doubling 0.069 k allocs: 0.568 MB 0.069 k allocs: 0.568 MB 1
Smets_Wouters_2007/lyapunov/gmres 0.301 k allocs: 2.65 MB 0.301 k allocs: 2.65 MB 1
Smets_Wouters_2007/qme/doubling 0.3 k allocs: 0.623 MB 0.3 k allocs: 0.623 MB 1
Smets_Wouters_2007/qme/schur 0.403 k allocs: 0.756 MB 0.403 k allocs: 0.756 MB 1
time_to_load 0.143 k allocs: 10.6 kB 0.143 k allocs: 10.6 kB 1

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

@codecov-commenter
Copy link

codecov-commenter commented Nov 28, 2025

Codecov Report

❌ Patch coverage is 98.36066% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.64%. Comparing base (f4a8b7e) to head (601a9cd).

Files with missing lines Patch % Lines
ext/StatsPlotsExt.jl 98.36% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (f4a8b7e) and HEAD (601a9cd). Click for more details.

HEAD has 16 uploads less than BASE
Flag BASE (f4a8b7e) HEAD (601a9cd)
21 5
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #198       +/-   ##
===========================================
- Coverage   87.46%   76.64%   -10.83%     
===========================================
  Files          20       20               
  Lines       12865    12652      -213     
===========================================
- Hits        11253     9697     -1556     
- Misses       1612     2955     +1343     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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