Reputation: 3852
I have a boxplot:
fig, ax = plt.subplots(1,1)
bp = df.boxplot(column='transaction_value',
by='store_type', grid=True,
ax=ax, showfliers=True)
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
ax.set_ylim([0, 800])
ax.set_ylabel('transaction_value')
plt.show()
I have a seaborn stripplot:
bplot=sns.stripplot(y='transaction_value', x='store_type',
data=df,
jitter=True,
marker='o',
alpha=0.1,
color='black')
When I try to overlay the stripplot on the boxplot, it deletes the first boxplot (on the very far left).
fig, ax = plt.subplots(1,1)
bp = df.boxplot(column='transaction_value',
by='store_type', grid=True,
ax=ax, showfliers=True)
bplot=sns.stripplot(y='transaction_value', x='store_type',
data=df,
jitter=True,
marker='o',
alpha=0.1,
color='black')
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
ax.set_ylim([0, 500])
ax.set_ylabel('transaction_value')
plt.show()
How can I stop this from happening?
a
transaction_value store_type
0 30.927648 express
1 20.356693 extra
2 48.201950 metro
3 77.213957 metro
4 15.482211 superstore
5 85.794876 superstore
6 16.199844 extra
7 0.007816 superstore
8 50.925737 metro
9 81.393811 metro
10 7.616312 superstore
11 82.172441 metro
12 49.608503 extra
13 71.907878 metro
14 85.833738 superstore
15 88.131029 express
16 11.541427 extra
17 89.759724 metro
18 96.435902 superstore
19 91.984656 superstore
20 67.795293 metro
21 39.806654 superstore
22 39.565823 metro
23 37.507718 superstore
24 37.918300 metro
25 18.599158 metro
26 3.815219 extra
27 83.210068 express
28 3.988503 extra
29 94.298953 superstore
a = pd.read_clipboard()
fig, ax = plt.subplots(1,1)
bp = a.boxplot(column='transaction_value',
by='store_type', grid=True,
ax=ax, showfliers=True)
bplot=sns.stripplot(y='transaction_value', x='store_type',
data=a,
jitter=True,
marker='o',
alpha=0.1,
color='black')
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
ax.set_ylim([0, 500])
ax.set_ylabel('transaction_value')
plt.show()
Upvotes: 0
Views: 289
Reputation: 40667
@ImportanceOfBeingErnest provided a solution in comments while I was typing, but I was going to suggest something else:
For better consistency, I would recommend to use seaborn to do the boxplots as well, this should ensure that both plots are laid out the same way,
fig, ax = plt.subplots(1,1)
sns.boxplot(y='transaction_value', x='store_type', data=df, ax=ax,
color='w')
sns.stripplot(y='transaction_value', x='store_type', data=df, ax=ax,
jitter=True,
marker='o',
alpha=0.1,
color='black')
ax.set_ylabel('transaction_value')
plt.show()
Upvotes: 1