matplotlib xticks标签重叠 [英] matplotlib xticks labels overlap

查看:342
本文介绍了matplotlib xticks标签重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am not able to get nicer spaces between the xticks with the following code:

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()

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

How to get more space between the xticks so they do not look like overlapped anymore?

谢谢.

推荐答案

您可以尝试更改图形尺寸,xticklabel的尺寸,其旋转角度等.

You can try changing the figure size, the size of the xticklabels, their angle of rotation, etc.

# 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')

这篇关于matplotlib xticks标签重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆