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
Using ginput on a plot_date plot doesn't return datetime #7462
changed the title [-]Using ginput on a plot_date plot doeson't return datetime[/-][+]Using ginput on a plot_date plot doesn't return datetime[/+]on Nov 15, 2016
@tacaswell, can you please provide more information on the unit framework? Where in the code is it? I traced the function calls to BlockingMouseInput but I don't understand exactly how and where the mouse click coordinates are retrieved. Perhaps some information on that might also help me.
After thorough investigation of this bug as a team for our project at UofT, we came to the conclusion there isn't a really good solution to this problem.
We had the following fix in mind:
introduce a new parameter to ginput called converter which we will use to pass the desired converter function to ginput.
the converter function passed must take a float
The output of ginput() will now be the output of the converter function or a float if no converter is passed in.
Advantages of the fix:
1.The float that ginput() generates, can be converted to any type as long as the user provides a converter function.
2. You can technically pass in any function in place of the converter and use it to deduce information about the data
Disadvantages of the fix:
The output type of ginput() is inconsistent. This is a sign of bad software design although python permits it.
No real change to what's available now. The only thing is that the conversion step is done implicitly. This however, introduces the inconsistency in the output type of ginput().
Conclusion
The current design of ginput() is the most appropriate one. Conversions should be done explicitly to preserve the consistency of the output type of ginput(). Perhaps there may be another way to work this out by introducing polymorphism for all the possible types that could be used in a plot and change ginput to have an output of the parent type, however that will require quite a bit of restructuring and the benefit may not be worth the effort.
@tacaswell, do you still consider this a feature that's worth implementing? If not, can we close this issue? Thanks
I think the best approach would be to add an example that uses ginput + num2date to get out the desired datatime with some comments about how if you are using unitful data + ginput the user is responsible for taking care of the inverse transformation.
Thanks @tacaswell. Under what subsection of examples should we add this example? Also, are we responsible for adding the HTML pages and links for the new example we will create?
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!
I think most converters have inverses? If so we could just have an option to ginout to change the output type. The inverse isn't unique, but could at least be in the units/type the user wants. Note that the cursor status in the lower right already does this.
Hi! I wanted to work on this. I have a question -- since ginput returns (x, y), should we pass two separate converters in case the axes are using different units (for example plotting datetime against floats, etc)?
Looking back through the comments, the recommendation from @tacaswell was that this option should not be added to ginput. Instead, an example should be added to the documentation showing how to convert the output of ginput back to the desired units. That was 5 years ago. To be clear: is the reversal of this guidance coming because of changes in mpl in the interim, or is it just a different opinion?
Activity
[-]Using ginput on a plot_date plot doeson't return datetime[/-][+]Using ginput on a plot_date plot doesn't return datetime[/+]tacaswell commentedon Nov 20, 2016
Not sure if we actually know enough to be able to do this in general right now.
datetime is handled through the unit framework which (roughly) works by:
I think you are asking to also provide an inverse from float -> the input data type with units.
It should be possible to add this in a back compatible way, but will need a bit of thought.
For this particular case, iirc the float is
seconds from 1900days from 0001-01-01 UTC, plus 1.efiring commentedon Nov 20, 2016
It's days from a ridiculous but common sort of origin, long, long, ago. See http://matplotlib.org/api/dates_api.html for the explanation.
dstansby commentedon Feb 28, 2017
Would it not be possible to use
num2dateto convert the output ofginputdirectly to a datetime? http://matplotlib.org/api/dates_api.html#matplotlib.dates.num2datemitko1994 commentedon Mar 16, 2017
@tacaswell, can you please provide more information on the unit framework? Where in the code is it? I traced the function calls to
BlockingMouseInputbut I don't understand exactly how and where the mouse click coordinates are retrieved. Perhaps some information on that might also help me.added unit tests file for issue matplotlib#7462
mitko1994 commentedon Apr 3, 2017
After thorough investigation of this bug as a team for our project at UofT, we came to the conclusion there isn't a really good solution to this problem.
We had the following fix in mind:
ginputcalledconverterwhich we will use to pass the desired converter function to ginput.floatAdvantages of the fix:
1.The float that ginput() generates, can be converted to any type as long as the user provides a converter function.
2. You can technically pass in any function in place of the converter and use it to deduce information about the data
Disadvantages of the fix:
Conclusion
The current design of ginput() is the most appropriate one. Conversions should be done explicitly to preserve the consistency of the output type of ginput(). Perhaps there may be another way to work this out by introducing polymorphism for all the possible types that could be used in a plot and change ginput to have an output of the parent type, however that will require quite a bit of restructuring and the benefit may not be worth the effort.
@tacaswell, do you still consider this a feature that's worth implementing? If not, can we close this issue? Thanks
tacaswell commentedon Apr 3, 2017
I think the best approach would be to add an example that uses
ginput+num2dateto get out the desired datatime with some comments about how if you are using unitful data + ginput the user is responsible for taking care of the inverse transformation.mitko1994 commentedon Apr 10, 2017
Thanks @tacaswell. Under what subsection of examples should we add this example? Also, are we responsible for adding the HTML pages and links for the new example we will create?
7 remaining items
github-actions commentedon Apr 5, 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!
jklymak commentedon Apr 5, 2023
I think most converters have inverses? If so we could just have an option to ginout to change the output type. The inverse isn't unique, but could at least be in the units/type the user wants. Note that the cursor status in the lower right already does this.
oscargus commentedon Apr 5, 2023
Marking as good first issue. Basically the following should be done:
matplotlib/lib/matplotlib/backend_bases.py
Lines 2941 to 2960 in 8ca75e4
Note that one will have to dig a bit deeper, as we are not really interested in the string formatting of the cursor position here.
turnipseason commentedon May 29, 2023
Hi! I wanted to work on this. I have a question -- since ginput returns (x, y), should we pass two separate converters in case the axes are using different units (for example plotting datetime against floats, etc)?
efiring commentedon May 29, 2023
Looking back through the comments, the recommendation from @tacaswell was that this option should not be added to ginput. Instead, an example should be added to the documentation showing how to convert the output of ginput back to the desired units. That was 5 years ago. To be clear: is the reversal of this guidance coming because of changes in mpl in the interim, or is it just a different opinion?