1 回答

TA贡献1906条经验 获得超10个赞
如果我理解正确,您需要垂直的白色网格线而不是您当前获得的水平线。这是一种方法:
创建一个轴对象ax,然后将其分配给sns.boxplot. 然后,你可以选择使用一个布尔参数,以显示其网格线ax.xaxis.grid和ax.yaxis.grid。由于您需要垂直网格线,因此请关闭 y 网格 ( False) 并打开 x 网格 ( True)。
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import numpy.random as rnd
fig, ax = plt.subplots() # define the axis object here
some_x=[1,2,3,7,9,10,11,12,15,18]
data_for_each_x=[]
for i in range(0, len(some_x)):
rand_int=rnd.randint(10,30)
data_for_each_x.append([np.random.randn(rand_int)])
sns.set()
sns.boxplot(data=data_for_each_x, showfliers=False, ax=ax) # pass the ax object here
ax.yaxis.grid(False) # Hide the horizontal gridlines
ax.xaxis.grid(True) # Show the vertical gridlines
如果您想同时显示 x 和 y 网格,请使用 ax.grid(True)
添加回答
举报