0

I've been going off of this answer which said to use orientation=u'horizontal', so I made this simple code:

import matplotlib.pyplot as plt

plt.bar(x=[1,2,3],
        height=[1,2,3],
        orientation=u'horizontal')
plt.show()

But I get the error: TypeError: the dtypes of parameters y (object) and height (int64) are incompatible.

Why is that? Is it because I am specifically rotating a barplot?

P.S. I tried specifying y, even though I'm not sure it is appropriate in a barplot. That also gave an error.

profPlum
  • 403
  • 4
  • 12
  • 1
    Maybe use `barh`? Or `plt.barh(y=[1,2,3], width=[1,2,3])` – JohanC Jun 19 '21 at 15:29
  • You should post this as an answer it works – profPlum Jun 19 '21 at 15:35
  • That being said do you know why my code doesn't work? Is it a bug with matplotlib? – profPlum Jun 19 '21 at 15:36
  • I don't know what version of matplotlib you are using, seems like the term **orientation** is not a parameter of bar plot. [here] (https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html). When you remove it from the expression, the code runs fine. For horizontal as mentioned above do use barh. – DragonsCanDance Jun 19 '21 at 15:40

1 Answers1

1

the link you provided is 7 years old

in an oler version of matplotlib 2.1.0 it says about orientation as a parameter and says

orientation : {‘vertical’, ‘horizontal’}, optional

This is for internal use, please do not directly use this, call barh instead.

https://matplotlib.org/2.1.0/api/_as_gen/matplotlib.pyplot.bar.html

virxen
  • 408
  • 4
  • 12