python - pandas matplotlib x 轴仅每五个位置标记一次
问题描述
我在 matplotlib 中绘制一个条形图,其中包括从具有相同 x 轴的 3 个不同数据帧中的一列中获取数据,并将条形图并排绘制
它主要工作,除了x轴只标记每五个位置而不是所有位置?如何标记每个位置?
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)
给出:
解决方案
也许尝试:
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)
推荐阅读
- python - 根据 df1 中的值在 df2 中保留一列
- node.js - 尝试在 Docker 中更新 NPM:代码 EISDIR
- python - 使用 SQLite3 TypeError 在 Python 中出现参数错误:+ 的不支持的操作数类型:'sqlite3.Cursor' 和 'str'
- c# - 在以前的属性中选择 null
- android - I18nManager.forceRtl(false) 在 android 中不起作用
- vue.js - Vue - 为输入文本设置默认值
- javascript - 如何让 chrome 重新渲染 iframe
- java - Istio 使用通配符路径返回“RBAC: access denied”
- python - Python实例变量在运行时变成类变量
- json - 在 Redshift 中拆分一个 varchar 列