-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
plt.step(..., where="auto") #5855
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 am so-so on this. I assume the use case here is histograms? In that case I think we need a set of histogram (n vals, n+1 edges) high-level plotting tools. Embrace the unix philosophy of small tools that do one thing well rather than the app philosophy of one tool that does a lot of things so-so. Put another way, |
Actually the use case is time series with measurements corresponding to intervals (e.g.: average velocity between to times), rather than to discrete times. So semantically I'd think it belongs in |
I suppose one major problem here is to define where the vertical lines should start/end. Is it safe to assume without loss of generality that this would always be |
if your x is [1, 2, 3] and y is [6, 7, 8, 9], then you have conversely if x is longer than y then you start with horizontal, but all ends are well defined. |
Makes sense, I misread the vertical/horizontal above. Still maybe something like "auto0", with |
|
Is there some advantage to auto versus just checking the vector sizes? |
I am 👍 on this, but it should be opt-in via
|
|
+1 for „edges“. „bin-edges“ would already be an assumption on the semantics of the data. „Interlaced“ feels a bit more vague. |
It's actually not clear at all to me why one may want to call this "edges"? (I... don't see the semantic association.) |
"where do you want the line at y[i] to extend to?" "pre" means before x[i], "post" means after, "mid" means centered on x[i], "edges" mean treat x[i] and x[i+1] as edges of where to draw.... But I'm not strongly against "auto", its just not clear that the way to get "auto" is to provide N+1 x-values.. |
But it's not necessarily n+1 x values: the proposal suggests to make this also work both when there's one more x values than y values (then the first and last lines are horizontal), and when there's one more y values than x values (then the first and last lines are vertical). |
What would “auto” do if x and y have the same length? “edges” would clearly raise an error. |
It would raise an error; it's not clear what's "clear"(er) in "edges" raising an error... |
Yeah, sure, transpose by whatever vector is longer... |
Let me also throw in two words: I think prior to naming one should see in how far this new functionality is to be a drawstyle and hence part of the |
I think(?) it's not worth trying to shoehorn this into drawstyles/Line2D because of the mismatch between x and y sizes. I would just make step output a Line2D with one entry for each visual vertex (unlike "steps-pre"/"steps-mid"/"steps-post" which has one entry for every other visual vertex, and creates the "actual" vertices of the drawn line on-the-fly). I feel like most of the names proposed here are too semantically linked to the idea of using this to draw histograms; while I am fine with that application (despite the preference of putting that functionality in hist()) this was really not the original motivation of this proposal. |
But the original motivation was the same value over an averaging interval. Why wouldn't the interval be specified by "edges"? |
Well, the |
Note that the original motivation was also about being able to switch the x and y axises (if your time is on the vertical axis), in which case the meaning of "enclosed" and "opened" would be switched. |
The problem with The case discussed here is probably more an edgecase, so Concerning |
It was this use-case that brought me here: I frequently have lists of n+1 bin edges and n bin values -- e.g. from numpy.histogram or from an incremental histogramming tool -- and want to plot them in a (maybe filled) "stepped histogram" format. Unless I'm missing something, this isn't currently easy in matplotlib: I have to create an extra duplicate value on one end of the values array, remind myself of the semantics of the "where" argument, explicitly type that somewhat cryptic (from a histogramming mindset) extra arg for all my data lines, etc. This feels a long way from the "make simple things simple" philosophy :-) Automatically inferring a sensible rendering behaviour for n_y = n_x - 1 would be one way to do it, hence my finding this ticket... but a dedicated set of histogram rendering commands would be even better. Is there any concrete plan or ticket for this? I'd be happy to contribute... |
What is the status of this? Based on #6669 it seems we would at least want a If I understand it correctly what we want is essentially the outcome of but to be able to get it as Is that correct? If so, any guidelines on how this should be implemented other hiding it directly in step and to raise an error if one tries to supply |
That's my understanding of the desired outcome, too: this would be really nice to have, rather than having to hack an obsfucatory duplication of the last counts entry every time. |
@agbuckley Check #15019 |
After a short look at #15019 I would like to reinterate the idea of making this a drawstyle. If you let
This would be a rather unfortunate design, because there is no way to e.g. update such line. In contrast, if the |
Closed by #18275. |
I would like to suggest adding a fourth option for the
where
kwarg ofplt.step
:where="auto"
. This would takex
andy
arguments which differ by 1 (in either way) in length, and make a step plot that either has horizontal segments at both ends (iflen(x) == len(y) + 1
) or has vertical segments at both ends (iflen(y) == len(x) + 1
).As far as I know, currently, to make such a plot one must manually duplicate either the first or the last value in the shorter of the two arrays, which is a bit awkward. Additionally,
"auto"
-mode would make it much easier to rotate such a plot by 90° (in the "vertical" direction): you'd just have to switch thex
andy
arguments, without worrying about whether you need to changewhere
or which element to duplicate.Thoughts?
The text was updated successfully, but these errors were encountered: