Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.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 使用seaborn/matplotlib箱线图时的勾选频率_Python_Matplotlib_Seaborn_Boxplot - Fatal编程技术网

Python 使用seaborn/matplotlib箱线图时的勾选频率

Python 使用seaborn/matplotlib箱线图时的勾选频率,python,matplotlib,seaborn,boxplot,Python,Matplotlib,Seaborn,Boxplot,我正在用seaborn绘制一系列箱线图 sns.boxplot(full_array) 其中full_数组包含200个数组。 因此,我在x轴上有200个方框图和刻度,从0到200 xtick彼此太近,我只想展示其中的一些,例如,标记为xtick每隔20个左右 我尝试了上述几种解决方案,但都不起作用 每次我对XTICK进行采样时,我都会得到错误的刻度标签,因为它们的编号从0到N,单位间距 例如,使用行ax.xaxis.set\u major\u定位器(ticker.multiplelotator

我正在用seaborn绘制一系列箱线图

sns.boxplot(full_array)
其中
full_数组
包含200个数组。 因此,我在x轴上有200个方框图和刻度,从0到200

xtick彼此太近,我只想展示其中的一些,例如,标记为xtick每隔20个左右

我尝试了上述几种解决方案,但都不起作用

每次我对XTICK进行采样时,我都会得到错误的刻度标签,因为它们的编号从0到N,单位间距

例如,使用行
ax.xaxis.set\u major\u定位器(ticker.multiplelotator(20))
我每20次会得到一个带标签的xtick,但标签是1、2、3、4,而不是20、40、60、80


感谢所有乐于助人的人。

seaborn箱线图使用固定定位器和固定格式器,即

print ax.xaxis.get_major_locator()
print ax.xaxis.get_major_formatter()
印刷品

<matplotlib.ticker.FixedLocator object at 0x000000001FE0D668>
<matplotlib.ticker.FixedFormatter object at 0x000000001FD67B00>

如果x轴有数据类型字符串怎么办?在这种情况下,您能告诉我如何设置XTICK的频率吗?@weeFWWQG3请不要在对其他问题的评论中提出新问题。如果此问答不能解决您的问题,请提出一个新问题,并说明您的问题。
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import seaborn.apionly as sns
import numpy as np

ax = sns.boxplot(data = np.random.rand(20,30))

ax.xaxis.set_major_locator(ticker.MultipleLocator(5))
ax.xaxis.set_major_formatter(ticker.ScalarFormatter())

plt.show()