Repository navigation
Allow lists of quantities to be converted in Matplotlib unit converter - #7037
Conversation
|
Hi there @dstansby 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃. I noticed the following issue with this pull request:
Would it be possible to fix this? Thanks! If there are any issues with this message, please report them here. |
mhvk
left a comment
There was a problem hiding this comment.
Nice simple addition and much more works! Wonderful! I do think I would count this not working as a bug, and thus think we should back-port it. Could you add an entry in CHANGES.rst in the 2.0.4 section?
Also, could you add a simple test to visualization/tests/test_units.py?
|
|
||
| with quantity_support(): | ||
| plt.plot([1, 2, 3] * u.m, [3, 4, 5] * u.kg) | ||
| plt.axhline(10 * u.cm) |
There was a problem hiding this comment.
A horizontal line would have to use the units of the vertical axis, no? So, maybe 10 * u.g?
There was a problem hiding this comment.
Woops, that's right. I've tried that, and it throws a different error. I think there's going to need to be a bit more fixing on the Matplotlib side to use axhline actually. I'll let you know when I've had a chance to make it work properley!
There was a problem hiding this comment.
Okay, with matplotlib/matplotlib#10143 and this PR axvline and axhline work properly with units. Shall I wait until the Matplotlib one is merged, and then come back to this PR?
|
I think I found the reason for the test failures. When you fix it, could you also squash the commits? (I usually do this by rebasing, but if you don't know how to do it, don't worry about it.) |
|
@dstansby - great that you found where the matplotlib problem is (I'm not sure about the solution, though; it would seem you'd need another transformation -- I don't think you can count on multiplying with units to necessarily work in other unit systems). For this PR, is there another matplotlib command that is enabled by your change? If so, I think we should add another test that uses that and mark the present test as |
|
🎉 I think that errobar plotting works with this PR - I'll try and put in a test |
|
Would be wonderful if |
|
Bah as far as I can see it's all working locally (maybe because I'm running the |
|
With this PR, and matplotlib/matplotlib#10206, which has just gone into Matplotlib and will be in version |
|
OK, makes sense. It will be nice if units work even more automatically! |
|
Okay, this change requires Matplotlib version 2.2 or later, but I guess that's better than nothing. In theory it's all good to go now. |
mhvk
left a comment
There was a problem hiding this comment.
@dstansby - this looks good to me, but I don't understand the many circleci failures. It seems there is something wrong with it that has little to do with your PR. @astrofrog or @bsipocz - do you have a better idea?
Anyway, approved as a PR.
|
Odd, circleci doesn't even seem to be pulling the branch properly. I'll try closing and re-opening to power cycle CI. |
|
🤦♂️ I just force pushed this from an old local copy. Will update it back to the version that was approved when I get to my other computer tomorrow... |
|
RIGHT sorry for the faff, this is definitely now ready. pinging @astrofrog @mhvk |
|
Looks all OK to me. @bsipocz - at some point, you moved the milestone, but is there any reason not to backport to astropy 2.0.x? Matplotlib 2.2 still supports python2. |
|
It looks it was just a placeholder to avoid unnecessary remilestoning before every bugfix. Moved it back to 2.0.x. (As a consequence, I'm happy to deal with moving the changelog to it's place if you after this is merged). |
Allow lists of quantities to be converted in Matplotlib unit converter
Allow lists of quantities to be converted in Matplotlib unit converter
Allow lists of quantities to be converted in Matplotlib unit converter
Quite a lot of the unit support built into Matplotlib, and quite a lot of the internals, works on lists of unit-like object. This lets a list of quantities be converted fine using the Matplotlib unit converters in Astropy.
As an example, this change makes vlines and hlines work in Matplotlib: