Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Feature: Plot multiple bars with one call#11048
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
I'm a bit confused by this taking the data row-wise. So for consistency I would suggest to do the same here as well. |
I did it the way it is because I think most users will have their data for each bar in an series of arrays and would like to just put them into one bar call. The post referenced in the feature request (https://stackoverflow.com/questions/14270391/python-matplotlib-multiple-bars?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) does it that way so thats what I went with. I can change it if that's what you want but I'd like to be sure that others agree with you about it first. |
I'd need to double check, but I somewhat suspect you broke the API for |
In terms of plotting just a single bar graph, nothing is changed. I could, however put in new documentation describing how optional parameters are treated by the multibar code. |
anntzer commentedApr 14, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I think there's a pretty bad issue right now of rows vs columns in this kind of data (see e.g.#8092) and would suggest we figure out the best way to handle that first (my opinion is in the linked issue, but mostly I just want things to be consistent :-)) before making the situation even more tangled... |
A cultural standard is to organize data in tables. Those tables are read column by column. Example (from the famous work by Jean Baptiste Perrin about Brownian Motion) While of couse equally possible, I rarely see anyone creating such table by aranging the independent data horizontally. Example from Spreadsheet software: More specifically, reading in data into numpy from such table with n rows and m columns, e.g. via To be honest I'm at loss as to why one would suddenly use the transpose of that. (I know that matplotlib already has this transposed concept e.g. in the case of asymmetrical errorbars, where data needs to be row-wise, but that is surely confusing.) |
Ok. I made it take the data column-wise. |
lib/matplotlib/axes/_axes.py Outdated
The height(s) of the bars. | ||
2-dimensional arrays represent grouped bars. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think this should be
scalar or array-like of shape(N,) or shape(N,M)
right? (same below for barh)
And the role of N and M should be explained here. Something like
..., where N is the number of bar positions (same as the length of
x
) and M the number of groups.
Data StructureI think this is good. It is consistent with how DocumentationA minor point (but not negligible) is the example:
(I think I slightly prefer the first option, simply because it keeps the number of different gallery examples low. But maybe it's also good to show an example with more than two groups?) Finally, I think this grouping mostly makes sense for categorical data. Since matplotlib supports categorical data in the sense of strings supplied to plotting function, wouldn't it be nice to have this incoorporated in the example? So using |
While I understand the motivation, I have several concerns about this this. If this goes in I suspect we will almost immediately get a request for this, but stacked. The obvious way to add this is to add some grouped-only relevant kwargs which is something we diffidently want to avoid. I am also concerned about the change in return type based on the type of the input. The How does this play with datastructures that are easy to get out of pandas dataframes? I think this may be better as a new top-level function to avoid the variable return types, easily support the stacked case, and to (without concern for back compatibility) deal with the broadcasting of all the parameters issues. |
With the function now taking the data in columns, this plays very well with pandas. As stated above this is one of the motivations to use columns instead of rows. If
It seems though that it does not allow for the I cannot say much about the other points - probably they are all valid. |
If you guys could give me a checklist with what you want me to do I would be happy to oblige. |
We talked about this on the weekly call and the consensus is that this is a very useful functionality, but the front end complexity people are going to want is quite large and going to rapidly grow (give a mouse a cookie....) and adding a large branch that recursively calls back into it's self is too much complexity on the implementation side. The route we would like to see this take is to create a new function ( What kwargs from What are the desired semantics on:
Is it worth making a new I think the next step is to write out the docstring for what this function! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
See comments for details
tldr; make this a separate function
Still thinking of working on this one@UTSC-SISYPHUS ? |
Sorry, I had exams. I will still work on it. I'll get to it this weekend. I could do with a bit of information on the |
Added documentation for new function. Please give me feedback. |
It looks like this currently only consists of documentation semantics. The code is simply |
I had this working in another function but changes were requested. I'm asking if I should write the code for the documentation as it is now or if I should make some more changes first. |
Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it. |
Superseded by#24313. Please move further discussion there. |
Uh oh!
There was an error while loading.Please reload this page.
PR Summary
Added the ability to give a 2D matrix to
pyplot.bar
to plot multiple bar graphs with one call.Example :
will create

#10610
PR Checklist