pandas Python条形图中的重叠轴标签 [英] Overlapping axis labels in Pandas Python bar chart
问题描述
是否可以在轴标签之间创建空间?它们是重叠的(30个标签在一起)使用python pandas ...
Is it possible to create space between my axis labels? They are overlapping (30 labels crunched together) Using python pandas...
genreplot.columns =['genres','pct']
genreplot = genreplot.set_index(['genres'])
genreplot.plot(kind='barh',width = 1)
我会发布图片,但是我没有10个声誉.....
I would post a picture, but i don't have 10 reputation.....
推荐答案
我尝试重新创建您的问题,但不知道您的标签确切是什么,我只能对这个问题提供一般性评论.您可以采取一些措施来减少标签的重叠,包括标签的数量,字体大小和旋转度.
I tried recreating your problem but not knowing what exactly your labels are, I can only give you general comments on this problem. There are a few things you can do to reduce the overlapping of labels, including their number, their font size, and their rotation.
这里是一个例子:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
genreplot = pd.DataFrame(columns=['genres', 'pct'])
genreplot.genres = np.random.random_integers(1, 10, 20)
genreplot.pct = np.random.random_integers(1, 100, 20)
genreplot = genreplot.set_index(['genres'])
ax = genreplot.plot(kind='barh', width=1)
现在,您可以设置标签5
Now, you can set what your labels 5
pct_labels = np.arange(0, 100, 5)
ax.set_xticks(pct_labels)
ax.set_xticklabels(pct_labels, rotation=45)
作为进一步参考,您可以查看此页面,以获取有关xticks
的文档和yticks
:
For further reference, you can take a look at this page for documentation on xticks
and yticks
:
这篇关于 pandas Python条形图中的重叠轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!