-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Figure.set_size_cm and Figure(figsize_cm=) as an alternative to figsize/set_size_inches #12402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
pads and margins are often specified in points and ems, as well as cms and ins, so the motivation for something more general was not AU or picometers. |
It's a fair point, and I agree that generalizing the units in the various points would be nice. There are many places where I feel the required units are basically arbitrary. Like in annotations, you can choose between 'offset points' or 'offset pixels'. I often eyeball numbers because I cannot use consistent unit throughout. I just fear such a task will require a lot of changes to be done, and done well, taking considerable time. And while we wait, I still need to chug down inches just to set the figure size. |
I'm -1 on a new kwarg. I personally think we should allow |
I would be ok with that. A string parser is not great, but not any worse than what we do we colors. |
That sounds reasonable to me. But I'd give the folks who didnt like the idea of a string parser a day or so to register their concerns before I spent a lot of time making a PR ;-) |
You would indeed save two characters of typing.
It is of course an advantage not having to remember the number 2.54. Essentially instead of the number 2.54 the user will then need to remember which methods exist for centimeters and which don't and possibly their return type. As soon as the "5cm" is introduced, where do you stop, i.e. would At which point do you evaluate the conversion? Since In total, I think this requires a lot of thought and a clear concept. |
On Fri, Oct 05 2018, Elan Ernest wrote:
I wouldn't complete oppose the option to use other units, but I think
it'll somehow need to be consistent. If you specified the figure size
in centimeters, will `fig.get_figwidth` return inches? Or centimeters?
Good point. I don't think I ever needed to get back the figure/sizes out
of a plot, but I can see where this could become necessary.
If internally the units are inches, and the return values are inches,
and if the units provided to functions, as floats, are interpreted as
inches, I would _still_ be fine with it.
string? Would the `dpi` also get its centimeter-equivalent `dpcm`? Or
would there be a `fig.dpcm_scale_trans` transform?
dpi has no proper metric equivalent. If I need to calculate the density,
I actually go through inches myself. However, most of the time, I
specify the density directly.
At which point do you evaluate the conversion? Since `8.0 ==
(8.0/2.54)*2.54` is `False`, I suppose it might matter.
I would convert the units to the internal representation (inches)
directly after accepting them. That is, the input units would be mostly
cosmetic.
|
There was a big discussion about this in #9226. I didn’t come away from that with many compelling arguments for anything other than allowing simple strings. I think the only issue is that we want to be consistent across the library in what strings are chosen I’m not convinced there is any need to worry about the return type units. If folks are going to do math with the return type they can look up whatever conversion they need. If at some point we want to be pedantic and include inverse units like dpi I suppose that could happen but we don’t get an issue every few months asking to specify dpi in dots per millimeters, so I think that could be put off. |
Still waiting patiently for this. It's amazing how anything involving printing is stuck with inches, but I'd expect something a bit better out of a scientific plotting package... :/ |
Printing is done in points, and a point is 1/72 of an inch. Given there is an easy conversion to centimeters, I don't think there is any appetite for a new way to parse the fig size options. If you wanted to propose a |
On Mon, May 04 2020, Jody Klymak wrote:
Printing is done in points, and a point is 1/72 of an inch. Given
there is an easy conversion to centimeters, I don't think there is any
appetite for a new way to parse the fig size options. If you wanted to
propose a `set_figsize_cm` thats probably not too hard to add...
I know the conversion is not hard to do, it's just annoying.
My underlying units are metric to begin with, the sheet itself is
defined in metric terms and I usually want a 1:1 scale for the final
print. The rulers I have around are all metric... I mean, I lack the
general "feel" of what a inch is to begin with. To me it's just this
random scaling factor I keep seeing everywhere and prevents me to have a
direct mapping to the unit I'm familiar with... :/
|
dpi is in inches, and points are in inches. When we pursued this before, people went down the rabbit hole of wanting dots-per-cm, etc. The other problem was that I appreciate the historic artifact of inches is un-aesthetic to those raised on metric. But it is pretty ingrained in the printing and publishing world, so not a completely irrational choice. And dividing by 2.54 is pretty easy if a bit more typing. |
On Mon, May 04 2020, Jody Klymak wrote:
dpi is in inches, and points are in inches. When we pursued this
I have no such trouble for dpi to be defined in terms of inches though.
You almost never have to deal with density directly and by virtue I know
what 100 vs 300 DPI looks like.
I appreciate the historic artifact of inches is un-aesthetic to those
raised on metric. But it is pretty ingrained in the printing and
publishing world, so not a completely irrational choice. And dividing
by 2.54 is pretty easy if a bit more typing.
You underestimate how often this pops up, in several spots. In every
script. It's a very frustrating itch that reinforces itself.
Sizing text is somewhat less of an issue because, like for DPI, print
has engrained us with what "point" means in practical terms. It also
helps that having to size text precisely is also much more rare: it's
usually ok to have something which is readable.
|
Well, I understand that inches and dpi units are used widely in the publishing industries. That's why we are not proposing to drop them in favour of international metric system units! Just give the freedom to the people using other metric standards, to work in the way they prefer (which by the way are the majority of the people living on the planet, take a look to this picture). I think those who claims that the cost-benefits ratio for supporting arbitrary units deep down in the library is not good enough for its technical complexity, greatly underestimate the political and marketing reasons for doing it. I fully agree with wavexx that nowadays people expect this sort of things from a scientific visualisation software. Saying to the user community "take this soup or leave it", sound a bit... imperialistic. In my opinion, a reason to fork, for example. Please take this a critique in a constructive way and not as an insult. I know how much work it is to create and maintain a software package, which, amazingly, you and the community are providing for free. Many benefit (including myself) from your work. Nevertheless on this point, in my opinion there is room for improvement. Sincerely,
|
@alkhwarizmi I appreciate your feedback. API design is a trade-off between features, simplicity, consistency and backward-compatibility. In this context I don't see a way of adding the feature "metric figure sizes" without significantly affecting the other design aspects. Some additional comments.
|
Is the exposed API the only real issue here? As in: Like I said before, I don't actually mind if the unit I extract from the internal APIs are inches. I rarely do so and I wouldn't mind an inconsistency there. Perhaps not the best, but still not too far from your example of abusing DPI=100 to have useful pixel sizes. To reiterate, the problem for me is not the easiness of the conversion. Maybe if you're used to the imperial system you somewhat tolerate having these random factors in the code that's ok, but to me all printing units (from inches to "points") are totally meaningless in a metric system. I pick up a ruler and measure stuff, and I need to undo/redo this crap all the time. We're quite lucky in the end that most of the time we don't need physical units to match, so what I personally do is render everything proportionally and to just scale down. I know it's a straw-man argument, since this is what historically has always been done, so .. I'm actually fine with hacks like what I proposed above as long as it improves the everyday ergonomics. |
(Just to be clear, note that many of the core devs here who have expressed concern about the proposal (here or in #9226) are not from the US, but indeed from metric system places, namely the EU (well, I don't know about the Canadian here :-)).) |
As a dev myself, I would also frown on such a proposal. It's objectively ugly, especially considering how the documentation would look like, and also regarding the inconsistency of the input/output. So, yes, I also agree with you! But wow, I'm super-frustrated with the status quo. |
Anyone is of course, welcome to take up #12415. But it was closed because its hard to come up with an API that everyone will like that allows you to specify two different units. In the end I did not deem it worth pushing. SO my opinions here are just my paraphrase of the concensus from those discussions. |
@timhoffm I am speaking as a user and I don't know enough about the matplotlib details to propose a new API. I would like to give back to the community by coding something, but I think it would be better to start with something easier ;). I can imagine that what I have in mind could be really too much or even impossible to achieve (if changes in the API would be needed). However, here is the idea:
Final point. As my comment was somehow not completely technical, and I pretty much like the idiom you suggested at point 2 (and other suggested as well), I wonder what would happen if you change all the examples in the documentation including that idiom, and you make 50% of the examples with Thank you again for the opportunity to speak. Very much appreciated. |
@alkhwarizmi Please read the discussions in #9226 and #12415 |
This is a very succinct description of the tensions in maintaining an old, large, and widely used project @wavexx ! |
@alkhwarizmi What you are scetching is a more general layout system allowing Artists in relative or absolute positions given in various units. This would be a solution to be considered if starting from scratch. Unfortunately, Matplotlib does work differently internally and the general solution would require a major redesign. But even when limiting to figure size: Holding hidden state and changing the return value of If anything, something like #12415 seems most viable to me. My impression is that none of the core developers sees this as a priority, justifying to work on this themselves. It would need an external champion to work through all the details and push it forward. If somebody is interested in working on this, please comment in #12415. In #18360 I've written an example for best practices working with different units. This is as good as we can get without introducing new API. |
looking back, it seems #12415 was close, but a couple of core devs were somewhat negative, and folks stopped reviewing it, and I lost interest compared to other things I thought were more worth harassing potential reviewers for. So, if someone really wants to take the torch up and make a new PR based off #12415, I wouldn't object. In the meantime, I think #18360 is pretty useful. |
If somebody wants to pick up #12415, please comment on that PR. We will then re-review the PR to determine if the concept has fundamental approval among core developers. This makes sure, that your work on the PR can get accepted. |
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! |
Reviving the spirit of matplotlib#12402 and matplotlib#12415, because both had significant user votes on GitHub. This PR is intentionally minimal to only expand the `figsize` parameter when creating a figure. This should be the most relevant use case. Later changing the figure size or reading it is probably less necessary. The minimal approach removes the need to track and return sizes. It is just an enhanced specification capability which directly parses to the internally used inch unit.
Reviving the spirit of matplotlib#12402 and matplotlib#12415, because both had significant user votes on GitHub. This PR is intentionally minimal to only expand the `figsize` parameter when creating a figure. This should be the most relevant use case. Later changing the figure size or reading it is probably less necessary. The minimal approach removes the need to track and return sizes. It is just an enhanced specification capability which directly parses to the internally used inch unit.
Reviving the spirit of matplotlib#12402 and matplotlib#12415, because both had significant user votes on GitHub. This PR is intentionally minimal to only expand the `figsize` parameter when creating a figure. This should be the most relevant use case. Later changing the figure size or reading it is probably less necessary. The minimal approach removes the need to track and return sizes. It is just an enhanced specification capability which directly parses to the internally used inch unit.
Reviving the spirit of matplotlib#12402 and matplotlib#12415, because both had significant user votes on GitHub. This PR is intentionally minimal to only expand the `figsize` parameter when creating a figure. This should be the most relevant use case. Later changing the figure size or reading it is probably less necessary. The minimal approach removes the need to track and return sizes. It is just an enhanced specification capability which directly parses to the internally used inch unit.
Reviving the spirit of matplotlib#12402 and matplotlib#12415, because both had significant user votes on GitHub. This PR is intentionally minimal to only expand the `figsize` parameter when creating a figure. This should be the most relevant use case. Later changing the figure size or reading it is probably less necessary. The minimal approach removes the need to track and return sizes. It is just an enhanced specification capability which directly parses to the internally used inch unit.
Reviving the spirit of matplotlib#12402 and matplotlib#12415, because both had significant user votes on GitHub. This PR is intentionally minimal to only expand the `figsize` parameter when creating a figure. This should be the most relevant use case. Later changing the figure size or reading it is probably less necessary. The minimal approach removes the need to track and return sizes. It is just an enhanced specification capability which directly parses to the internally used inch unit.
Reviving the spirit of matplotlib#12402 and matplotlib#12415, because both had significant user votes on GitHub. This PR is intentionally minimal to only expand the `figsize` parameter when creating a figure. This should be the most relevant use case. Later changing the figure size or reading it is probably less necessary. The minimal approach removes the need to track and return sizes. It is just an enhanced specification capability which directly parses to the internally used inch unit.
Reviving the spirit of matplotlib#12402 and matplotlib#12415, because both had significant user votes on GitHub. This PR is intentionally minimal to only expand the `figsize` parameter when creating a figure. This should be the most relevant use case. Later changing the figure size or reading it is probably less necessary. The minimal approach removes the need to track and return sizes. It is just an enhanced specification capability which directly parses to the internally used inch unit.
I grew tired of having to convert my units just for the sake of specifying the figure size. I'd like to specify the figure size directly in a metric unit, nominally centimeters (or millimeters, no difference). In most EU countries metric is the norm. I only have to deal with inches when looking at monitor sizes, printing, and matplotlib :(
I've found at least two issues about this: #1369 and the more generic #9226.
Of course, having support for generic unit specifiers would be nice, but I'm not entirely satisfied by the extra complexity of #9226. I'm also thorn about (size, unit) tuples, because I don't ever think I'm going to specify the figure size in AU, or picometers. Cm is regularly used for anything that fits paper.
I see two cases where inches are specified in the rc:
In the api, there is the figsize kwarg, I guess a pad_inches kwarg, and the set_size_inches method.
What abound the KISS approach: add a figsize_cm kwarg, pad_cm, and the set_size_cm method, and the two respective rcParams? Fully backward compatible, and allows metric countries to get by easily.
I could easily contribute such a patch.
The text was updated successfully, but these errors were encountered: