Skip to content

axes.margins set left/right and top/bottom independently #1912

Open

Description

@heavytull

axes.margins should allow setting left and right margins and top and bottom margins independantly. I often increase the top and right margins only so as to give room for the legend which sometimes takes place.

Activity

  1. mowa-lepota commented on Jul 31, 2013

    @mowa-lepota

    this would also be particularly useful when setting margins for logarithmic plots.

  2. tacaswell commented on Aug 2, 2013

    @tacaswell
    Member

    I am starting to work on this.

    It looks like the only major api break required is the no-argument return on ax.margins() (and by extension on plt.margins() .

    Everything else appears like it can be done in a backwards compatible way.

  3. tacaswell commented on Jan 21, 2014

    @tacaswell
    Member

    flagged this as 1.4, but it might have to slide.

    I am closing both of the PR's that try to address (#2263 and #2276) as neither seems to address this in the right way.

  4. modified the milestones: v1.4.x, v1.4.0 on Feb 20, 2014
  5. modified the milestones: v1.4.x, on Sep 5, 2014
  6. petehuang commented on Dec 30, 2016

    @petehuang
    Contributor

    This is still unaddressed, I believe. The PRs pointing to this issue have good discussion, would recommend reading.

    Recommend labeling as Difficulty: Medium perhaps?

  7. heavytull commented on Jan 3, 2017

    @heavytull
    Author

    it's been some time since i reported this wish / request, nearly three years and half later it is still an open issue!

  8. AdrienLemaire commented on Mar 8, 2017

    @AdrienLemaire

    was just looking for this, too bad it's not possible

  9. removed this from the milestone on Oct 3, 2017
  10. 7 remaining items

  11. modified the milestones: v3.6.0, v3.7.0 on Jul 8, 2022
  12. github-actions commented on Dec 22, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  13. kingyue737 commented on Jan 5, 2024

    @kingyue737

    @github-actions status:active

  14. github-actions commented on Jan 6, 2025

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  15. added
    keepItems to be ignored by the “Stale” Github Action
    on Jan 6, 2025
  16. boyanpenkov commented on Jul 14, 2026

    @boyanpenkov

    I suspect this might not be considered a good first issue (a la https://github.com/matplotlib/matplotlib/contribute), would it?

  17. timhoffm commented on Jul 14, 2026

    @timhoffm
    Member

    I'm personally not a fan of the "good first issue" label, as it has recently attracted mainly low-quality contributions (some "good first issues" with >10 closed solution attempts). So I'm hesitant to use that label,

    The topic itself is not too difficult I think. You should understand the autoscaling mechanism, and there's a bit of API discussion that we'd need to have together up-front. From the pure implementation side, this should be relatively straight forward. If you or somebody else has interest, please speak up and we'll figure out a way forward.

  18. boyanpenkov commented on Jul 14, 2026

    @boyanpenkov

    Hey Tim -- thanks for the fast response, and the pointer to the autoscale docs, which I will read...

    I am very much interested, but have an administrative constraint that I supposed many folks here will empathize with: the need to placate a thesis committee with something presentable by the end of week, as opposed to a durable solution that will last for a good long while.

    I'm leaving this thread open and would like to do this, but can't specify a timeline.

    Apropos, the revolting hack I will use to eyeball myself a passable figure in the next half hour is something like:

    x_min, x_max = ax.dataLim.intervalx
    y_min, y_max = ax.dataLim.intervaly
    
    ax.set_xlim(0.95*x_min, x_max)
    ax.set_ylim(0.95*y_min, y_max)
    ax.margins(0, 0) 
    
    

    For context, this need stems from my repeated use of:

     ax.spines["top"].set_visible(False)
     ax.spines["right"].set_visible(False)
    

    This then seems to leave too much whitespace on the top and right...

    Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    New featurekeepItems to be ignored by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions