1 回答

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊
如果我理解正確,您需要垂直的白色網(wǎng)格線而不是您當(dāng)前獲得的水平線。這是一種方法:
創(chuàng)建一個(gè)軸對(duì)象ax,然后將其分配給sns.boxplot. 然后,你可以選擇使用一個(gè)布爾參數(shù),以顯示其網(wǎng)格線ax.xaxis.grid和ax.yaxis.grid。由于您需要垂直網(wǎng)格線,因此請(qǐng)關(guān)閉 y 網(wǎng)格 ( False) 并打開(kāi) x 網(wǎng)格 ( 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
如果您想同時(shí)顯示 x 和 y 網(wǎng)格,請(qǐng)使用 ax.grid(True)
添加回答
舉報(bào)