NF - Added set_size_cm and get_size_cm for figures#5104
NF - Added set_size_cm and get_size_cm for figures#5104sameer wants to merge 5 commits intomatplotlib:masterfrom sameer:set-size-centimeters
Conversation
|
Thank you for your contribution. I am -.5 on this. It has come up before and was rejected for reasons I don't recall exactly. If we do merge this, it should be a minimal pass-through to |
|
I just made a change: instead of creating separate methods for metrics, I added an optional kwarg "metric" which is by default false for the get/set size functions. @tacaswell is this better? |
|
While I appreciate the contribution as well as the motivation for handling metric units, I don't think that either form (two more methods, or a kwarg) is a good idea. One basic problem is that we already have a somewhat confusing situation with respect to units, with dots, points, relative font sizes, and inches. Adding in one more--cm--in a couple of places doesn't add much real functionality or usability, and doesn't make the situation more consistent or less confusing, but it does add a little more complexity. In addition, having a |
|
@efiring I agree, it doesn't make sense to add a metrics argument to a set_size_inches function. @efiring , is there some alternative you would suggest? |
|
Having a metric kwarg is far worse. I was thinking more of def set_size_cm(self, w, h=None, **kwargs):
return self.set_size_inches(w*in_to_cm, h*in_to_cm if h is not None else None, **kwargs) |
|
@tacaswell Looks good, I'll do that quick |
…assed to inch functions
|
On 2015/09/19 1:12 PM, Thomas A Caswell wrote:
What's the point of letting h be optional? This won't handle the But I still think adding these methods is ad-hoc API bloat, and not a |
|
@efiring Shouldn't we be avoiding changing the name of the functions? There are already so many examples out there written with set_size_inches in the documentation and on StackOverflow. |
|
Yes, something like |
|
I wonder how @rmorshea's work on traitlets might help us here. If everywhere we accepted a physical length we could specify a unit, that would be universally consistent, localize the complexity and be the most flexible (likely). @rmorshea or @ellisonbg: I'd appreciate your thoughts about using traitlets for physical units. |
|
Probably the best way would be to have a |
|
@rmorshea I prefer to avoid passing numbers as strings; perhaps an alternative would be to use a tuple in which the first element would be the numeric value and the second would be the unit. |
|
@efiring tuples seem reasonable. An entirely different option would be to have a |
|
What is the status of this pull request? |
|
Internally, the size of a figure is stored in inches (and will probably stay that way until 'dpc' overtakes 'dpi' in the rest of the world and 'point' is not defined as 1/72 of an inch). The question is if the extra API size is worth users who prefer to work in cm to not have to do a conversion them selves. It looks like this needs a bit more input cleanup in I am still -.5 on this. I would not merge it, but would not protest if someone else did. |
|
Coming back to this a year later, I am mostly convinced by @efiring 's suggestion of adding |
|
Personally, I'd be interested in a more general parsing of units for most things. I wrote a little |
|
@dopplershift also maintains (at least one) unit library |
|
It'd be more accurate to say I'm a very invested user in the pint unit library. I don't think it's useful to rely on a full math capable, dimension tracking library when all we need internally is handling units for length. I don't have much of an opinion on |
|
@dopplershift The only reason for a small unit package is that there are many many other places where a dimension is asked for, and in many of them a unit could be useful. i.e. all the various paddings are specified in different units. It would be nice to allow all those dimensions to be specified in a library-consistent way. I also think it'd make user code more readable. I suppose you could do this with |
|
Added a MEP: #9226 |
|
Closing in favour of |
Provides for a "native approach" to figure sizing in centimeters, as requested in question 14708695 on StackOverflow
https://stackoverflow.com/questions/14708695/specify-figure-size-in-centimeter-in-matplotlib