3

I was trying the following code:

fig, ax1 = plt.subplots()
#data is a geopandas DataFrame 
data.plot(ax=ax1, kind='bar', color= barcolor, width= 0.8)
ax1.set_yticklabels(ax1.get_yticklabels(), weight='bold')
ax1.set_xticklabels(ax1.get_xticklabels(), rotation=0, weight='bold', size=12)

Only x-axis gets affected by this code and y-axis labels are getting removed.

Subrat Prasad
  • 133
  • 1
  • 9

2 Answers2

4

Change get_yticklabels() to get_yticks works for me:

fig, ax1 = plt.subplots()
ax1.bar([0,1],[2,3])
ax1.set_yticklabels(ax1.get_yticks(), weight='bold')
ax1.set_xticklabels(ax1.get_xticks(), rotation=0, weight='bold', size=12)

Output:

enter image description here

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
1

Here is the answer for reasons behind this kind of error. It's because matplotlib avoids static positioning. Adding the following code just after data.plot() helped too:

fig.canvas.draw()
Subrat Prasad
  • 133
  • 1
  • 9