Skip to content

add rc param for centimeter support #1369

Closed

Description

@andreas-h

It would be great if I could specify a figsize in centimeters. I would like to write

import matplotlib as mpl
mpl.rcParams['lengthunit'] = 'c'
figure(figsize=(12, 8))

instead of

figure(figsize=(12/2.54, 8/2.54))

I think this would be a great addition for the non-anglo-saxon world ;)

Activity

  1. mdboom commented on Oct 12, 2012

    @mdboom
    Member

    I agree -- requiring inches there is rather archaic. However, I don't think an rcParam is the right way to do it. I'd rather see the unit be part of the parameter, e.g.:

    figsize=((12, 'cm', (8, 'cm'))

    or

    figsize=('12cm', '8cm')

    Neither of those are perfect (more thinking needs to be done), but I think changing global state for this could be too problematic.

  2. pwuertz commented on Oct 12, 2012

    @pwuertz
    Contributor

    Absolutely love the idea of using "unit-aware" objects instead of numbers for defining lengths and sizes as also stated in #1109.

    @mdboom, would you be in favour of a unit-class that supports arithmetic operators like __add__, __mul__, __sub__, etc? So for example one could define figsize = (12*cm, 8*cm) or figsize = (12*cm, 8*cm + 1*mm).

  3. pwuertz commented on Oct 12, 2012

    @pwuertz
    Contributor

    @WeatherGod, Thanks for the hint! I think I was looking for something like that for quite some time ^^. That tight integration with numpy seems nice. Is anyone imagining the plotting of such data with unit aware axis labelling too? ;)

  4. dmcdougall commented on Oct 12, 2012

    @dmcdougall
    Member

    @pwuertz I don't see the benefit of unit aware plotting/axis labelling. It requires almost no effort to append '(cm)' or '(s)' to my x-axis label. Date/time units are useful, and already supported. What is requested here is nothing to do with unit-aware plotting but physical figure attributes. Perhaps I'm overlooking something.

  5. pwuertz commented on Oct 12, 2012

    @pwuertz
    Contributor

    @dmcdougall Of course this is about figure attributes and my original question to mdboom was if he is in favor of a unit class that would support arithmetic operations with ints and floats.

    WeatherGod came up with that project that takes this one step further. If matplotlib adapted this package, the idea of supporting it at plot level came to my mind. Think about plotting an array of times. When you decide that you want the plot to be displayed in us instead of ms you could change that at a single position in the code. Rescaling all of the plotted data and adding the correct unit to the label would be handled automatically. Just an idea, completely off-topic.

  6. dmcdougall commented on Oct 12, 2012

    @dmcdougall
    Member

    When you decide that you want the plot to be displayed in us instead of ms you could change that at a single position in the code.

    That's a fair point.

  7. pelson commented on Oct 16, 2012

    @pelson
    Member

    @pwuertz : I think it is worthy of a MEP. I love the idea, and would like to see this idea get developed further and discussed before we can make a sound decision about it. Would you be willing to write a MEP?

    EDIT: Fixed typo from PEP->MEP. Doh!

  8. dmcdougall commented on Oct 16, 2012

    @dmcdougall
    Member

    Would you be willing to write a PEP?

    MEP?

  9. pelson commented on Oct 16, 2012

    @pelson
    Member

    MEP?

    Ja ja. Sorry 😃.

  10. pwuertz commented on Oct 17, 2012

    @pwuertz
    Contributor

    A MEP for general support of physical units that focuses on properties like figsize and discusses optional features like plotting of unit-aware data?

  11. mdboom commented on Oct 17, 2012

    @mdboom
    Member

    I think such a MEP would be great. I see the two pieces: one for parameters like figsize, possible font size as well) and one for unitized data. These pieces can be implemented somewhat independently (i.e. we can do one without the other), but it might be worth discussing them at the same time to contemplate some consistency between the two. We already have lots of the infrastructure for unitized data that is currently used for dates, and it would be worth investigating how that could be extended. For a long time, I've felt good docs on how to add a new unit would be very helpful -- it's not a part of the code that I personally understand very well.

  12. pelson commented on Oct 18, 2012

    @pelson
    Member

    it's not a part of the code that I personally understand very well.

    Likewise. I wonder who does?

  13. WeatherGod commented on Oct 18, 2012

    @WeatherGod
    Member

    On Thursday, October 18, 2012, Phil Elson wrote:

    it's not a part of the code that I personally understand very well.

    Likewise. I wonder who does?

    Sadly, I think it was John, but I don't think he implemented it. I know it
    was added to address needs from NASA for the MSL lander (or was that the
    spline filter for paths?). There was a email in the past six months where
    he discusses the history of various parts of mpl. In fact, it might have
    been in response to my email awhile back about how mpl got me a job -- in
    case anyone wants to go searching.

    Ben Root

  14. pwuertz commented on Oct 19, 2012

    @pwuertz
    Contributor

    When I got a little more time I'd like to work on these layout managing ideas and possibly write a MEP for that. As pointed out, this would also include support for units. The question is whether to wait for that layout management project (which might be a really long time) or to implement an unit aware figsize option as a more "short term" solution.

  15. 8 remaining items

  16. modified the milestones: , on Sep 24, 2017
  17. oscarbranson commented on May 3, 2018

    @oscarbranson

    Another +1 for implementing this in rcparams. Would be great to be able to 'set and forget' metric units.

  18. jklymak commented on May 3, 2018

    @jklymak
    Member

    There is even a semi-abandoned MEP: #9226

    I think the easiest least-painful idea would be a new method that was able to parse strings for width and height: fig.set_size(width='15cm', height='2in'). Some will complain about hokey parsing, but...

  19. github-actions commented on Feb 28, 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!

  20. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Feb 28, 2023
  21. oscargus commented on Feb 28, 2023

    @oscargus
    Member

    This would still be useful in quite a lot of situations. The most progressed PR seems to be #12415 with quite a lot of discussions about the API.

  22. jklymak commented on Feb 28, 2023

    @jklymak
    Member

    I came away from that process convinced this is just they way it is. Figure size is one thing, but points and dpi are deeply embedded in the library.

  23. wavexx commented on Apr 7, 2025

    @wavexx
    Contributor

    Thanks to @timhoffm ! Small detail with huge usability improvement!

  24. removed
    keepItems to be ignored by the “Stale” Github Action
    on Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions