Skip to content

Improve plot output (hatching, unit formatting, mean lines, etc.)#171

Merged
andreww merged 16 commits intoGreenScheduler:mainfrom
sadielbartholomew:plotting-improvements
Nov 28, 2025
Merged

Improve plot output (hatching, unit formatting, mean lines, etc.)#171
andreww merged 16 commits intoGreenScheduler:mainfrom
sadielbartholomew:plotting-improvements

Conversation

@sadielbartholomew
Copy link
Member

@sadielbartholomew sadielbartholomew commented Nov 24, 2025

Address points in #153, excluding unit tests for plotting (best set those up once we agree on what the output plot should look like, IMO, to save any need to continuously tweak the desired output images to test against), with some further plotting improvements thrown in for good measure (call me sad but I enjoy making a nice plot 🙂 ).

All up for discussion and happy to edit or revert anything if folks don't like it - but I for one think the time series plot (shown with --plot) from our POC plot PR is much more readable, accessible and good-looking after these updates.

Updates

This PR implements the following:

  • applies an accessible style sheet from the matploltib and colours so that those e.g. with some form of colour blindness can understand the plot better - without relying on colour to convey anything (e.g. hatching also distinguishes the two job run windows, see below) esp. by adding a legend to stop red and green being the only way to tell apart the now and optimal cases;
  • add hatching in different directions to emphasise and distinguish the two windows and make the nature of the overlap region clear, plus window black borders for emphasis against the CI forecast background;
  • if there is an overlap, as determined by the optimal run start value and now run end value, add a patch corresponding to the style of the overlap region to the legend (otherwise leave it off the legend to avoid cluttering it);
  • start y axis at 0 to remove gap below CI filled-in curve, (though leave the gaps to each side of the x axis because that makes clear the 48-hour window extent of the CI forecast which I think is useful, else it could be assumed it goes on further at least to the right for later times);
  • unit formatting, noting that to avoid the need to check for (La)TeX availability on the local system, we can use the Mathtext lightweight formatter bundled with matploltib itself;
  • add horizontal dashed lines to illustrate the mean for the and optimal values, helping to illustrate the two quoted CI figures in context of the plotted windows;
  • format datetimes on x axis tick labels so that the date is only shown against the day start (might be easier to see what I mean by looking at the 'after' output plots below) making it IMO much quicker to comprehend the datetime span;
  • improve the formatting of the title to avoid duplication of units and other text, etc;
  • add some small subtle scatter points to show the actual forecast values, which I think it nice in terms of making any interpolation for the trend line clear.

Before and after

I used the following command near to time of posting to test: cats -d 100 --loc RG2 --plot ('no overlap' examples) and cats -d 600 --loc RG2 --plot (overlap examples). Starting with after, since that's the output from this PR so most relevant...

After (result on this/PR branch)

Example with no overlap of windows

cats_prver_nooverlap

Example with overlap of windows

cats_prver_withoverlap

Before (result on main branch)

Example with no overlap of windows

cats_main_nooverlap

Example with overlap of windows

cats_main_withoverlap

@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

❌ Patch coverage is 4.16667% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.00%. Comparing base (61eee71) to head (6d3d6bf).
⚠️ Report is 43 commits behind head on main.

Files with missing lines Patch % Lines
cats/plotting.py 4.16% 46 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #171      +/-   ##
==========================================
- Coverage   83.31%   80.00%   -3.32%     
==========================================
  Files          15       15              
  Lines         737      770      +33     
==========================================
+ Hits          614      616       +2     
- Misses        123      154      +31     

☔ 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.

@andreww
Copy link
Collaborator

andreww commented Nov 28, 2025

Just starting a review here: first thing to say is that I really like the new plots!

Copy link
Collaborator

@andreww andreww left a comment

Choose a reason for hiding this comment

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

Looks good to me. Strikes me that the main plotting function does not contain any type hints but I think fixing that belongs in a different PR (if we want to be able to save a figure in a command line environment that will probably touch the arguments so let's fix that then - I'll add a comment to the relevant issue).

Also, I have everything running locally with python 3.14 so I'll bump the CI later too

ax.scatter(now_times, now_values, color=now_colour, s=8, alpha=0.3)
ax.scatter(opt_times, opt_values, color=optimal_colour, s=8, alpha=0.3)

def tick_formatting(x, pos):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Super minor comment but I would probably call this something like "readable_datetime_tick_formatter" (and then curse because I failed to find a reasonably short name)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, agreed that the title is too generic and doesn't explain it's purpose very well. If you can note that (or link to your comment here) on the new relevant issue, that would be great. Thanks for the prompt review :)

@andreww andreww merged commit 2abbf21 into GreenScheduler:main Nov 28, 2025
12 checks passed
@sadielbartholomew sadielbartholomew deleted the plotting-improvements branch November 28, 2025 15:01
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.

2 participants