Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在pandas.plot函数中减小x轴刻度之间的间距?_Python_Pandas_Matplotlib - Fatal编程技术网

Python 如何在pandas.plot函数中减小x轴刻度之间的间距?

Python 如何在pandas.plot函数中减小x轴刻度之间的间距?,python,pandas,matplotlib,Python,Pandas,Matplotlib,我创建了以下情节: 使用以下代码: dataframe_plot2.set_index('Class')[['HB ref', "HB tussenfase","HB raaigras"]].T.plot(kind='bar', stacked=True,width=0.1) plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.5)) 但是,x轴刻度之间的空间相当大。我希望这个距离能小一些。做这件事的简单方法是什么 网络上的许多页面解释了

我创建了以下情节:

使用以下代码:

dataframe_plot2.set_index('Class')[['HB ref', "HB tussenfase","HB raaigras"]].T.plot(kind='bar', stacked=True,width=0.1)
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))
但是,x轴刻度之间的空间相当大。我希望这个距离能小一些。做这件事的简单方法是什么

网络上的许多页面解释了如何在非常特定的情况下扩大空间,但没有说明如何减少空间。 e、 g

以前也有人问过类似的问题:但我不清楚答案

还检查了:

但这并没有提供我所需要的信息

我也不是在寻找滴答声的频率(比如)

我试过:

import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
dataframe_plot2.set_index('Class')[['HB ref', "HB tussenfase","HB raaigras"]].T.plot(kind='bar', stacked=True,width=0.1)
dataframe_plot2.xaxis.set_major_locator(plt.ticker.MultipleLocator(5))
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))

AttributeError: 'DataFrame' object has no attribute 'xaxis'

但这没有效果

更新: 运行:

结果:

编辑当前和预期输出:

当前:

预期:


与要增加间距的情况不同,在这种情况下,只有将图形变大的选项,可以通过几种方式减少刻度之间的间距。一个是与上述相反的,即使图形变小,但也可以使图形内的轴变小,或使轴内的内容变小。现在还不清楚你想要哪一个。谢谢你的回复。把数字缩小不是我想要的。此外,使轴更小似乎不是一个选项。“使轴内的内容变小”的确切含义是什么?当前x轴的数据范围类似于-0.3,2.3。如果改为
plt.xlim(-2,4)
则内容将缩小。@ImportanceOfBeingErnest我运行代码时,确实使空间变小了(编辑了原始问题)…但现在它的两侧有很多空白。有什么想法吗?你之前说过你不想让图形或轴变小,但这正是你在“预期”图片中所拥有的。与你想增加间距的情况不同,在这种情况下,只有将图形变大的选项,减少刻度之间的间距可能是可行的有几种方法。一种方法与上述方法相反,即缩小图形,但也可以缩小图形内的轴,或者缩小轴内的内容。不清楚您想要哪种。谢谢您的回复。缩小图形不是我想要的。也可以缩小斧头es更小似乎不是一个选项。您对“使轴内的内容更小”的确切含义是什么?当前x轴的数据范围类似于-0.3、2.3。如果改为
plt.xlim(-2,4)
则内容会缩小。@importantanceofbeingernest我运行代码时,它确实会缩小空间(编辑原始问题)。。。但现在它的两侧有很多空白。有什么想法吗?你之前说过你不想让图形或轴变小,但这正是你在“预期”图片中的想法。
import matplotlib.pyplot as plt
import matplotlib.ticker as tic
dataframe_plot2.set_index('Class')[['HB ref', "HB tussenfase","HB raaigras"]].T.plot(kind='bar', stacked=True,width=0.1)
tic.MultipleLocator(5)
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))
import matplotlib.pyplot as plt
dataframe_plot2.set_index('Class')[['HB ref', "HB tussenfase","HB raaigras"]].T.plot(kind='bar', stacked=True,width=0.1)
plt.xlim(-2, 4)
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))