Giter Club home page Giter Club logo

Comments (7)

aaronchucarroll avatar aaronchucarroll commented on July 24, 2024 1

Sorry, I got confused.

The expected behavior of matplotlib is for the categories to be displayed from bottom-to-top.
But within the categories, the bars should display in proper order of the legend.

The current barh function gives this plot with the sample code:
Screenshot 2024-06-07 at 10 38 29 AM

Flipping it with plt.gca().invert_yaxis() gives:
Screenshot 2024-06-08 at 3 24 26 PM

What we would ideally want is a barh function that preserves the X-Y-Z ordering from bottom to top while ordering the bars as C-B-A from bottom to top.

I am working on implementing this.

from pandas.

rhshadrach avatar rhshadrach commented on July 24, 2024

Thanks for the report. Can you provide a full reproducible example.

from pandas.

aaronchucarroll avatar aaronchucarroll commented on July 24, 2024

I was able to reproduce it with the following simple bar plot:

data = pd.DataFrame({
    'A': [3, 4, 2],
    'B': [1, 2, 3],
    'C': [4, 1, 2]
}, index=['X', 'Y', 'Z'])

data.plot.barh()
plt.show()

This is the produced output.
Screenshot 2024-06-07 at 10 38 29 AM

As reported, the legend follows the reverse order of the bars.

If this should be fixed I can begin working on a solution.

from pandas.

nateGeorge avatar nateGeorge commented on July 24, 2024

Thanks, the solution would just be plt.gca().invert_yaxis() I think.

from pandas.

rhshadrach avatar rhshadrach commented on July 24, 2024

I agree - this is a bit odd. I'm +1 on a fixing.

from pandas.

aaronchucarroll avatar aaronchucarroll commented on July 24, 2024

I did some further looking and this is expected behavior of matplotlib. The only fix then is to hardcode a y_axis flip. This would cause a lot of issues with backward compatibility and is generally bad practice. I think it should be left as is.

from pandas.

rhshadrach avatar rhshadrach commented on July 24, 2024

Thanks for reporting back.

I did some further looking and this is expected behavior of matplotlib.

Are there any links you can share in this regard?

from pandas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.