【问题标题】:matplotlib xticks labels overlapmatplotlib xticks 标签重叠
【发布时间】:2012-08-29 17:12:19
【问题描述】:

我无法使用以下代码在 xticks 之间获得更好的空间:

import random
import matplotlib.pyplot as plt

coverages = [random.randint(1,10)*2] * 100
contig_names = ['AAB0008r'] * len(coverages)
fig = plt.figure()
fig.clf()
ax = fig.add_subplot(111)

ax.yaxis.grid(True, linestyle='-', which='major', color='grey', alpha=0.5)

ind = range(len(coverages))
rects = ax.bar(ind, coverages, width=0.2, align='center', color='thistle')
ax.set_xticks(ind)
ax.set_xticklabels(contig_names)
#function to auto-rotate the x axis labels
fig.autofmt_xdate()

plt.show()

如何在 xticks 之间获得更多空间,使它们看起来不再重叠?

提前谢谢你。

【问题讨论】:

    标签: matplotlib bar-chart


    【解决方案1】:

    您可以尝试更改图形大小、xticklabels 的大小、它们的旋转角度等。

    # Set the figure size
    fig = plt.figure(1, [20, 8])
    
    # Set the x-axis limit
    ax.set_xlim(-1,100)
    # Change of fontsize and angle of xticklabels
    plt.setp(ax.get_xticklabels(), fontsize=10, rotation='vertical')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 2018-08-21
      • 2014-12-29
      • 2020-07-06
      相关资源
      最近更新 更多