0

I am plotting a bar chart in matplotlib which consists of take the data from a one column in 3 different dataframes with the same x-axis and plotting the bars side to side

It mostly works except that the x-axis only labels every fifth location instead of all locations? How do I label each location?

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(25,10))

plt.subplots_adjust(hspace=0.8, wspace=0.2)


x = df_rightmoveSmry.index

labels = list(df_rightmoveSmry['Adj Date'].astype(str).str[0:10])

y1 = df_rightmoveSmry['branches']
y2 = df_zooplaSmry['branches']
y3 = df_onthemarketSmry['branches']
ax.set_title('Number of estate agents on each Platform', fontsize=20)
ax.set_xticklabels(labels, rotation = 90, fontsize=20)
ax.yaxis.set_tick_params(labelsize=15)
ax.bar(x, y1, width=0.3)
ax.bar(x+0.3, y2, width=0.3)
ax.bar(x+0.6, y3, width=0.3)

gives:

enter image description here

nevster
  • 371
  • 3
  • 15

1 Answers1

0

Maybe try:

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(25,10))

plt.subplots_adjust(hspace=0.8, wspace=0.2)


x = df_rightmoveSmry.index

labels = list(df_rightmoveSmry['Adj Date'].astype(str).str[0:10])

y1 = df_rightmoveSmry['branches']
y2 = df_zooplaSmry['branches']
y3 = df_onthemarketSmry['branches']
ax.set_title('Number of estate agents on each Platform', fontsize=20)
ax.set_xticks(list(df_rightmoveSmry['Adj Date'].unique())) # <--- this line added
ax.set_xticklabels(labels, rotation = 90, fontsize=20)
ax.yaxis.set_tick_params(labelsize=15)
ax.bar(x, y1, width=0.3)
ax.bar(x+0.3, y2, width=0.3)
ax.bar(x+0.6, y3, width=0.3)
René
  • 4,594
  • 5
  • 23
  • 52