我试图在swarmplot的顶部使用seaborn的pointPlot绘制组明智的中值.即使我将pointPlot称为第二个,点图也会在swarmplot后面结束.如何更改“图层顺序”以使点图位于swarmplot前面?
datDf=pd.DataFrame({'values':np.random.randint(0,100,100)})
datDf['group']=np.random.randint(0,5,100)
sns.swarmplot(data=datDf,x='group',y='values')
sns.pointplot(data=datDf,x='group',y='values',estimator=np.median,join=False)
解决方法:
使用zorder属性设置正确的drawing order.
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pylab as plt
datDf=pd.DataFrame({'values':np.random.randint(0,100,100)})
datDf['group']=np.random.randint(0,5,100)
sns.swarmplot(data=datDf,x='group',y='values',zorder=1)
sns.pointplot(data=datDf,x='group',y='values',estimator=np.median,join=False, zorder=100)
plt.show()