如何创建具有 2 个 y 轴的 seaborn 箱线图?由于规模不同,我需要这个。我当前的代码将覆盖箱线图中的第一个框,例如。它由第一个轴的第一个数据项和第二个轴的第一个数据项填充。
import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
import seaborn as sns
df = pd.DataFrame({'A': pd.Series(np.random.uniform(0,1,size=10)),
'B': pd.Series(np.random.uniform(10,20,size=10)),
'C': pd.Series(np.random.uniform(10,20,size=10))})
fig = plt.figure()
# 2/3 of A4
fig.set_size_inches(7.8, 5.51)
plt.ylim(0.0, 1.1)
ax1 = fig.add_subplot(111)
ax1 = sns.boxplot(ax=ax1, data=df[['A']])
ax2 = ax1.twinx()
boxplot = sns.boxplot(ax=ax2, data=df[['B','C']])
fig = boxplot.get_figure()
fig
如何防止第一项被覆盖?
EDIT:
如果我添加位置参数
boxplot = sns.boxplot(ax=ax2, data=df[['B','C']], positions=[2,3])
我得到一个例外:
TypeError: boxplot() got multiple values for keyword argument 'positions'
可能是因为seaborn已经在内部设定了这个论点。