You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Units handling different with plot than other functions... #9713
The fact that neither case makes sense is maybe the fault of basic_units.py. But that asside, the fact that they are wrong in different ways is because plot and scatter handle units differently.
There is a discussion here: #9705 (comment) but basically plot updates units no matter if the units have already been set for an axis, whereas scatter and other functions do not updat ethe units if they have already been set.
This was the fundamental cause of the error in #9705 not being caught.
I think plot should be made consistent w/ the other plotting functions and only update the units if they have not been set.
I think future unit handlers should decide what to do if the new axis has different units.
@story645 Here is what I found most confusing: that we bother setting the axis units at all. We set the x-axis units, but then the next call to plot ignores whatever it is set to and re-translates the new values for x into floats using whatever the registry says to use. I guess thats good so we can plot different types of date objects on the same axis. But then why set the x-axis to have certain units?
That’d make a lot more sense modolo maybe always being able to plot an array of floats. If you want to mix types, either your converter can handle all the types you want to mix or you do the conversion by hand.
I think the only hang up is the converter gets called a bunch of times that don’t have real data in them.
As above, _base.cla() calls set_xlim(0, 1) which calls _process_unit_data(xdata=(0, 1) ) which of course calls self.xaxis.update_units(xdata). So, before the user has even had a chance to register a converter with the axis it has been attempted to set it (though it gets set to None, which is the pass through).
We could:
make the cla calls be less intrusive (either with a flag or?) and then make the first real call to get_units set the units.
Allow None passthrough to always work, but lockout other converters.
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!
Resolving this kind of discrepancy in the API is one of the overarching goals of the matplotlib/data-prototype work.
Resolving in the shorter term is likely a challenge to do without unintended side-effects. At its crux, I think this is due to some artists (scatter in particular, though I believe there are several others) which use the offsets feature of PathCollection and that gets resolved to floats early (and thus even if it passes through a convert_[xy]units call at draw time, no conversion will actually happen)
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!
Activity
jklymak commentedon Nov 7, 2017
Crossref #9336
jklymak commentedon Nov 9, 2017
@story645 Here is what I found most confusing: that we bother setting the axis units at all. We set the x-axis units, but then the next call to plot ignores whatever it is set to and re-translates the new values for x into floats using whatever the registry says to use. I guess thats good so we can plot different types of date objects on the same axis. But then why set the x-axis to have certain units?
Consider
It yields a nonsense plot and
If I don't
import pandas:story645 commentedon Nov 9, 2017
I think that's the point @anntzer was also making that once units are set, all plots on that axis should always be set.
anntzer commentedon Nov 9, 2017
(including when we are using the implicit, "pass-through" scalar converter -- I think this should disable setting another converter)
jklymak commentedon Nov 9, 2017
That’d make a lot more sense modolo maybe always being able to plot an array of floats. If you want to mix types, either your converter can handle all the types you want to mix or you do the conversion by hand.
I think the only hang up is the converter gets called a bunch of times that don’t have real data in them.
jklymak commentedon Nov 9, 2017
As above,
_base.cla()callsset_xlim(0, 1)which calls_process_unit_data(xdata=(0, 1) )which of course callsself.xaxis.update_units(xdata). So, before the user has even had a chance to register a converter with the axis it has been attempted to set it (though it gets set toNone, which is the pass through).We could:
clacalls be less intrusive (either with a flag or?) and then make the first real call to get_units set the units.Nonepassthrough to always work, but lockout other converters.I really don't understand the code in
matplotlib/lib/matplotlib/axes/_base.py
Line 1981 in 1ca3d1a
jklymak commentedon May 6, 2022
Here is another test based on our Quantities test in
test_units.py; basically the take home is that unit conversion is still almost completely broken:github-actions commentedon May 7, 2023
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!
QuLogic commentedon May 8, 2023
This is probably something for @ksunden?
ksunden commentedon May 9, 2023
Resolving this kind of discrepancy in the API is one of the overarching goals of the matplotlib/data-prototype work.
Resolving in the shorter term is likely a challenge to do without unintended side-effects. At its crux, I think this is due to some artists (scatter in particular, though I believe there are several others) which use the
offsetsfeature ofPathCollectionand that gets resolved to floats early (and thus even if it passes through aconvert_[xy]unitscall at draw time, no conversion will actually happen)github-actions commentedon Jun 5, 2024
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!