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)
添加回答
舉報