-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Suggesting improvements for bar
plot orientation behaviour.
#7994
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
If we were starting from scratch, that is probably a good idea, however, this change would break anyone who is currently working around this issue and using the I would almost be inclined to go the other way and remove the orientation kwarg and have |
@tacaswell Going the other way, in the sense of making the parameter Another option would be setting all default parameters to The anti-pattern issue is the unfortunate naming of |
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! |
Bug report
Bug summary
Guided by this tutorial example user could expect that the same applies for any graphing function with the keyword
orientation
. This isn't the default case when dealing withbar
. Specifyingorientation
keyword does not produce a rotated bar graph without manually setting the required parameters to avoid an error. To achieve the desired resultbarh
has to be used.Code for reproduction
Actual outcome
Current output for the above code will fail with an error.
Expected outcome
horizontal
. It's here to show that this isn't a bug, just weird usage (API).bar(self, left, height, width=0.8, bottom=None, **kwargs):
soleft
andheight
are set by default instead of being dependent onorientation
keyword in which case sometimesbottom
andwidth
parameters should be set instead, andheight
should becomewidth
. Error is raised when the methodbar
checks data for consistency but doesn't find any.bar
option andhorizontal
orientation secretly callsbarh
for drawing.vertical
orientation and should display correctly after the changes.Proposed change
In the case when
bar
is called withleft
andhorizontal
orientation:bottom
andleft
parameters should be exchangedwidth
andheight
should be exchangedChanges affect the
axes/_axes.py
file line no. 2034 where I propose that the values are manually exchanged, as in the code below, between the parameters before_process_unit_info
is called, that is immediately afterelif orientation == "horizontal"
line:Once this is implemented the listed examples above produce the expected result.
As a final thought I believe that solution is a bit "hackish" because it makes it harder to track data in the code for future devs/users as the switch happens relatively late inside
bar
. On the other hand its more user friendly because it reduces the amount of knowledge users have to have about how mpl works on the inside and makes it possible to more intuitively work with the mpl's API. In practice I believe code should be refactored to remove barh and standardize theorientation
keyword to work even in the cases of line plots or scatter plots. In principle this would consist of just a function that would switch thex
andy
data parameters. This would not be a very friendly change, and a bit of an overkill, as old code depending onbarh
would not work anyomre and at the same time a lot of mpl's code already seems to depend on the bar barh difference to work properly.Additionally, I have no idea if this change breaks something else, but so far it dosen't seem to have hurt my installation very much.
Matplotlib version
Sorry if this was an issue before, I looked but found none.
The text was updated successfully, but these errors were encountered: