Reputation: 331
I am working on plot with seaborn and want to plot two graphs in one figure.
data frame likes below.
liquidity lcindex
86493 0.611899 decline
86494 0.585814 revival
86495 0.553165 revival
86496 0.527779 revival
86497 0.521026 mature
86498 0.530813 decline
86499 0.530970 decline
86500 0.564019 revival
86501 0.564535 mature
86502 0.529418 start
86503 0.584290 start
86504 0.550692 start
86505 0.529517 start
86506 0.520906 start
86507 0.535492 revival
86508 0.653324 decline
86509 0.549327 revival
86510 0.528509 revival
86511 0.531548 revival
86512 0.555610 revival
86513 0.517208 decline
86514 0.516283 decline
86515 0.510123 mature
86516 0.512255 revival
86517 0.700632 mature
86518 0.505878 revival
86519 0.551810 revival
86520 0.812280 revival
86521 0.733664 decline
86522 0.714617 decline
first graph is below.
sns.stripplot(x="lcindex", y="liquidity", data=finaldf, jitter = True)
and I want to add line plot for mean value of liquidity by every x-values. I can obtain those values by
finaldf.groupby('lcindex')['liquidity'].mean().plot()
lcindex
decline 0.557899
growth 0.553409
mature 0.556915
revival 0.559233
start 0.585221
if I plot together the figure cropped the both edge side of plots but I want the graph looks like first graph and add lines.
ax1 = sns.stripplot(
x="lcindex", y="liquidity", data=finaldf, jitter=True,
palette="husl",
order=['start','growth','mature','revival','decline']
)
finaldf.groupby('lcindex')['liquidity'].mean().plot()
ax1.set_title ('title',fontsize=35)
ax1.set(xlabel='Life cycle Index', ylabel='Liquidity Index')
ax1.set(xticks=range(0, 5), xticklabels=["Start-up",'Growth', 'Mature', 'Revival',"Decline"])
How I can do it?
Upvotes: 1
Views: 2205
Reputation: 339250
You should be able to set the xlimits as usual
ax1.set_xlim(-0.5, 4.5)
Upvotes: 1
Reputation: 36545
Not exactly answering your question, but an alternative way to visualise your datapoints together with the means could be to draw your strip plot on top of a violin or box plot as in the last examples on http://seaborn.pydata.org/generated/seaborn.stripplot.html:
>>> ax = sns.boxplot(x="tip", y="day", data=tips, whis=np.inf)
>>> ax = sns.stripplot(x="tip", y="day", data=tips,
... jitter=True, color=".3")
Upvotes: 0