简体   繁体   English

如何在所有条形图子图上显示x轴标签?

[英]How to display x axis labels on all bar chart subplots?

Problem: 问题:

I am trying to display all of the labels on my bar chart subplots. 我试图在条形图子图上显示所有标签。 I have tried everything in this answer and this answer with no luck. 我试图在这一切的答案 ,这答案没有运气。

Data: 数据:

data = StringIO("""

Index-- --Rk    Passing-Player  Passing-Cmp Passing-Att Passing-Pct Passing-Yds Passing-Y/A Passing-AY/A    Passing-TD  Passing-Int Passing-Rate
0   0   1   Patrick Mahomes 364 573 63.5    4653    8.1 8.2 36  15  147.2
1   1   2   Davis Webb  22  41  53.7    300 7.3 8.3 2   0   131.2
2   2   3   Nic Shimonek    1   2   50.0    18  9.0 9.0 0   0   125.6
3   3   4   Jakeem Grant    1   1   100.0   72  72.0    92.0    1   0   1034.8
4   4   5   Jonathan Giles  1   1   100.0   3   3.0 3.0 0   0   125.2
5   5   6   Ian Sadler  0   1   0.0 0   0.0 0.0 0   0   0.0

""")

df = pd.read_table(data, delim_whitespace=True)

dfs = [df] * 9

Plotting code: 绘图代码:

fig, axs = plt.subplots(3,3, figsize=(10,10), sharey=True, sharex=False)
for ax,df in zip(axs.ravel(), dfs):
    ax.bar(df['Passing-Player'], df['Passing-Yds'])
    for tick in ax.get_xticklabels():
        tick.set_visible(True)

fig.autofmt_xdate(rotation=90)
fig.tight_layout(pad=2.0, w_pad=2.0, h_pad=10.0)
fig.savefig("tester.png")

Result: 结果:

在此输入图像描述

How can I display all of the x axis labels because in my real data each plot is different with different player names. 如何显示所有x轴标签,因为在我的实际数据中,每个绘图都有不同的玩家名称。

You need to remove fig.autofmt_xdate(rotation=90) as you aren't using dates and set the tick labels yourself with a rotation using ax.set_xticklabels(labels_go_here, rotation=90) 您需要删除fig.autofmt_xdate(rotation=90)因为您没有使用日期并使用ax.set_xticklabels(labels_go_here, rotation=90)设置刻度标签

fig, axs = plt.subplots(3,3, figsize=(10,10), sharey=True, sharex=False)
for ax, df in zip(axs.ravel(), dfs):
    ax.bar(df['Passing-Player'], df['Passing-Yds'])
    ax.set_xticklabels(df['Passing-Player'], rotation=90)

fig.tight_layout(pad=2.0, w_pad=2.0, h_pad=10.0)

plt.show()

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM