# Plot\_budget\_allocation creates misaligned axes

**URL:** <https://discourse.pymc.io/t/plot-budget-allocation-creates-misaligned-axes/17335>\
**Category:** v5\
**Tags:** pymc-marketing\
**Created:** [September 15, 2025, 9:09pm UTC](https://discourse.pymc.io/t/plot-budget-allocation-creates-misaligned-axes/17335 "2025-09-15T21:09:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fountainpen](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@fountainpen](https://discourse.pymc.io/u/fountainpen)\
**Post date:** [September 15, 2025, 9:09pm UTC](https://discourse.pymc.io/t/plot-budget-allocation-creates-misaligned-axes/17335/1 "2025-09-15T21:09:00Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/5/51bc4a90c3a1df6f972dac83c8a1c60b82eb40bf.png)

The attached plot was made with plot\_budget\_allocation. As you can see the y axes do not align. Is this intentional, or should they match on the grid?

---

<div class="post-metadata">

**Author:** ![cetagostini](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cetagostini/32/6967_2.png) [@cetagostini](https://discourse.pymc.io/u/cetagostini)\
**Post date:** [September 16, 2025, 12:24pm UTC](https://discourse.pymc.io/t/plot-budget-allocation-creates-misaligned-axes/17335/2 "2025-09-16T12:24:58Z")

</div>

Hey @fountainpen

Looks odd, but I’ll need to see your code or some reproducible example to find out. I try a few stuff without success reproducing. On the other hand, I’ll recommend to play with the new multidimensional class, and the plot suite, that should be better.

`pymc_marketing.mmm.multidimensional` ref: [MMM Multidimensional Example Notebook — Open Source Marketing Analytics Solution](https://www.pymc-marketing.io/en/stable/notebooks/mmm/mmm_multidimensional_example.html)

---

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [September 16, 2025, 12:38pm UTC](https://discourse.pymc.io/t/plot-budget-allocation-creates-misaligned-axes/17335/3 "2025-09-16T12:38:41Z")

</div>

Just a general note about MPL, it’s quite hard to align left and right axis gridlines. The grid always goes with the axis that it is added to (the left one in this case). See discussion [here](https://stackoverflow.com/questions/26752464/how-do-i-align-gridlines-for-two-y-axis-scales).

---

<div class="post-metadata">

**Author:** ![fountainpen](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@fountainpen](https://discourse.pymc.io/u/fountainpen)\
**Post date:** [September 16, 2025, 2:18pm UTC](https://discourse.pymc.io/t/plot-budget-allocation-creates-misaligned-axes/17335/4 "2025-09-16T14:18:56Z")

</div>

@cetagostini

I’m using the following plot style formatting

```auto
az.style.use("arviz-docgrid")
plt.rcParams["figure.figsize"] = [12, 7]
plt.rcParams["figure.dpi"] = 100

```

```auto
# Create budget bounds
percentage_flexibility = 0.3
num_optimization_periods = 15
budget_bounds = {
    channel: [
        (1 - percentage_flexibility) * current_weekly_spend[channel], 
        (1 + percentage_flexibility) * current_weekly_spend[channel]
    ]
    for channel in channel_columns
}

# Run budget optimization
allocation_strategy, optimization_result = mmm.optimize_budget(budget=total_weekly_budget, num_periods=num_optimization_periods, budget_bounds=budget_bounds, minimize_kwargs={“method”: “SLSQP”,“options”: {“ftol”: 1e-9, “maxiter”: 5000}})

```

```python
model_granularity = “weekly”
response = mmm.sample_response_distribution(allocation_strategy=allocation_strategy,time_granularity=model_granularity,num_periods=num_optimization_periods,noise_level=0.05,)

```

```auto
fig, ax = mmm.plot_budget_allocation(samples=response, figsize=(14, 8), original_scale=True)
ax.grid()

```
