Skip to content

Conversation

TeemuSailynoja
Copy link
Contributor

@TeemuSailynoja TeemuSailynoja commented Sep 30, 2025

Description

Ensure that y=0 is aligned between the primary and secondary y-axis in mmm.plot.budget_allocation.

Solution

If one axis includes negative, values the other is extended down so that the y=0 is aligned.

If all contributions would be fully negative (I don't know when this would happen...), the y=0 level is centered vertically on both axes.

Related Issue

  • Closes #
  • Related to #

Checklist


📚 Documentation preview 📚: https://pymc-marketing--1967.org.readthedocs.build/en/1967/

@github-actions github-actions bot added the MMM label Sep 30, 2025
Copy link

codecov bot commented Sep 30, 2025

Codecov Report

❌ Patch coverage is 4.54545% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.94%. Comparing base (539f32c) to head (6da79ec).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pymc_marketing/mmm/plot.py 4.54% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1967      +/-   ##
==========================================
- Coverage   92.18%   91.94%   -0.24%     
==========================================
  Files          67       67              
  Lines        8147     8169      +22     
==========================================
+ Hits         7510     7511       +1     
- Misses        637      658      +21     

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

@TeemuSailynoja
Copy link
Contributor Author

still needs tests to go through the combinations of negative positive and ensure that the axis limits are correct after the call.

Comment on lines +248 to +274
if ax.axes.get_ylim()[0] < 0 or ax2.axes.get_ylim()[0] < 0:
ylims1 = ax.axes.get_ylim()
ylims2 = ax2.axes.get_ylim()
# Find the ratio of negative vs. positive part of the axes.
if ylims1[1]:
ax1_yratio = ylims1[0] / ylims1[1]
else:
# Fully negative axis.
ax1_yratio = -1

if ylims2[1]:
ax2_yratio = ylims2[0] / ylims2[1]
else:
# Fully negative axis, may need to reflect the other
ax2_yratio = -1

# Make axis adjustments. If both axes fully negative, no adjustment.
if ax1_yratio < ax2_yratio:
ax2.set_ylim(bottom=ylims2[1] * ax1_yratio)
if ax1_yratio == -1:
# if the axis is fully negative, center zero.
ax.set_ylim(top=-ylims1[0])
elif ax2_yratio < ax1_yratio:
ax.set_ylim(bottom=ylims1[1] * ax2_yratio)
if ax2_yratio == -1:
# if the axis is fully negative, center zero.
ax2.set_ylim(top=-ylims2[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use NamedTuple or something. Quite confusing to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at this now, I fully agree. I also think that this is not capturing every possible combination the axes can get odd. I'll move this to a draft and rework it.

@TeemuSailynoja TeemuSailynoja marked this pull request as draft September 30, 2025 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants