-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
DOC: need discoverable documentation for Axes.fmt_xdata #9593
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
I'd rather suggest patching |
The present API is confusing and hard to remember, but telling users to replace Axes instance methods is not very appealing to me; it seems like the sort of thing that should be minimized. Asking them to set the value of an attribute, as is done presently, seems more normal. |
It's mostly a question of code philosophy, I think, and I am aware that patching methods is poorly regarded by many. I don't think there's much of a point in entering a long debate on the topic here so I'll just state that: When the intent is (effectively) to allow users to fully replace the behavior of a method by the behavior of another callable, I believe it is clearer to document the method as patchable, rather than to say "if you set this other attribute to a callable, then we'll call it instead of the original implementation" (in which case the end user (or at least I, when I encounter such APIs...) 1. needs to remember there's a second attribute name and what it is, and 2. will wonder whether the replacement implementation is used in all cases, or whether there are actually cases where it's not used). |
Patching the method is not quite the same as modifying its behavior via an attribute because the former blows away the original, complete with its docstring, while the latter allows one to easily return to the original. But maybe what is really needed here is a friendlier API, a single method that can be used to control either or both of the cursor readout formats. Maybe |
When patching at the instance level, you can, in fact, retrieve the original method, simply by
(note that you cannot
) While it is true that docstrings are lost, I think the docstring of a method such as Axes.format_xdata is really most used to generate rendered docs (or consulted with pydoc, etc.); it would seem quite rare to me to try to consult a docstring on a class that I'd be patching in the same interactive session (even via the fmt_xdata layer) (but what do I know...). |
I'd suggest this could go in the toc of I was going to agree w/ Eric that patching is obscure, but then I realized the only times I've had to chage the format was for moving between x,y and geographic co-ordinates with degrees minutes as dd mm.mmm , and that needs a function. |
@jklymak Even though it doesn't really help my argument :-) I don't think that's really an issue, its should be exactly the same thing to patch fmt_xdata or format_xdata (or do you have an example?) |
@anntzer I guess I was specifically thinking about def format_coord(x, y):
return 'x=%.4f, y=%.4f'%(map(x, y, inverse = True))
ax.format_coord = format_coord where But maybe I'm misunderstanding what you mean. |
Ah, sure, you're talking about overriding another method (and in this specific case it seems a fairly legit use case (yes, I know, you could write a custom formatter and install it as the Axis formatter... but why would you)). |
I think we should document setting Unfortunately |
and |
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! |
The Axes attributes,
fmt_xdata
andfmt_ydata
, are potentially very useful but incredibly obscure and minimally documented.The text was updated successfully, but these errors were encountered: