0

Here is my sorted series

      STATE_CD
AZ        1425
CA         897
TX         246
WA         184
IL         115
FL         112
GA         103
VA         101
PA         100
CO          89
NC          77
NV          70
NY          70
OH          62
MI          60
NJ          57

Trying to plot this as a bar chart

import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(30,16))
ax.bar(online_states.index, online_states, color='r')
ax.set_xlabel(xlabel='State', size=20)
ax.set_ylabel(ylabel='Online Students With Interactions' , color='b', size=20)
ax.set_xticklabels(online_states.sort_values(ascending=False).index, rotation=45, fontsize=20)
ax.set_yticklabels(online_states.sort_values(ascending=False), rotation=0, fontsize=20)
plt.show()        

But the output is showing the values inverted on the Y axis? Tried inverting Y axis and a few other things but never get expected result (with 1425 as the top value on the Y axis).

enter image description here

What am I doing wrong?

L Xandor
  • 1,659
  • 4
  • 24
  • 48
  • 1
    Is there a specific need for `ax.set_yticklabels()`? The default settings would likely be better because you're really just filling in text for the labels and therefore the scaling is not consistent either! (i.e. the distance from 101 -> 103 is the same as the distance 897 -> 1425). I recommend you comment this line out and see what the result is – Reedinationer Apr 03 '19 at 20:34
  • 1
    You are using your reversly sorted list of values as yticks. This is probably not what you want. – JohanL Apr 03 '19 at 20:34
  • Yes, removing the set_yticklabel helped, but I need to increase the font size of the tick labels. How do I do this without messing up the axis orientation? – L Xandor Apr 03 '19 at 20:48
  • You could use a method that gets all the text and then supply that to `ax.set_yticklabels()` along with the text size so that the numbers don't change, but get bigger? At https://matplotlib.org/api/axis_api.html?highlight=text%20size#yaxis-specific there is a `matplotlib.axis.Axis.get_label_text()` that maybe you could use. – Reedinationer Apr 03 '19 at 21:33
  • 1
    The underlying question seems to be how to change the label fontsize without using `set_yticklabels`. That is shown in the duplicates. – ImportanceOfBeingErnest Apr 03 '19 at 21:41

0 Answers0