简体   繁体   English

黑色条覆盖了我的x标签,用于matplotlib图?

[英]Black bar covering my x labels for matplotlib plot?

I am trying to play a figure and I am having a black box pop up on the bottom of the plot where the x labels should be. 我正在尝试播放人物,并且在图的底部应该有x标签的地方弹出一个黑匣子。 I tried this command from a similar question on here in the past: 过去我曾在类似的问题上尝试过此命令:

from matplotlib import rcParams
rcParams.update({'figure.autolayout': True})

But the problem was still the same. 但是问题仍然存在。 Here is my current code: 这是我当前的代码:

import pylab
from matplotlib import rcParams
rcParams.update({'figure.autolayout': True})

df['date'] =  df['date'].astype('str') 

pos = np.arange(len(df['date']))
plt.bar(pos,df['value'])
ticks = plt.xticks(pos, df['value'])

And my plot is attached here. 我的情节附在这里。 Any help would be great! 任何帮助将是巨大的! 在此处输入图片说明

pos = np.arange(len(df['date'])) and ticks = plt.xticks(pos, df['value']) are causing the problem you are having. pos = np.arange(len(df['date']))ticks = plt.xticks(pos, df['value'])引起您遇到的问题。 You are putting an xtick at every value you have in the data frame. 您要对数据框中的每个值都打一个xtick。

Don't know how you data looks like and what's the most sensible way to do this. 不知道您的数据是什么样子,什么是最明智的方式。 ticks = plt.xticks(pos[::20], df['value'].values[::20], rotation=90) will put a tick every 20 rows that would make the plot more readable. ticks = plt.xticks(pos[::20], df['value'].values[::20], rotation=90)将每20行放置一个刻度,这将使绘图更具可读性。

It actually is not a black bar, but rather all of your x-axis labels being crammed into too small of a space. 实际上,它不是一个黑条,而是所有x轴标签都塞满了一个很小的空间。 You can try rotating the axis labels to create more space or just remove them all together. 您可以尝试旋转轴标签以创建更多空间,或者将它们一起删除。

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

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